我已经子类化了UIActionSheet
,并且在-init
方法,我必须在调用 super 后单独添加按钮init
(无法传递 var_args)。
现在,它看起来像这样:
if (self = [super initWithTitle:title delegate:self cancelButtonTitle:cancel destructiveButtonTile:destroy otherButtonTitles:firstButton,nil]) {
if (firstButton) {
id buttonTitle;
va_list argList;
va_start(argList, firstButtton);
while (buttonTitle = va_arg(argList, id)) {
[self addButtonWithTitle:buttonTitle]
}
va_end(argList);
}
}
return self;
然而,我在这种情况下的具体用途是没有破坏性按钮、一个取消按钮和其他四个按钮。当它出现时,排序全部关闭,显示为
Button1
Cancel
Button2
Button3
就像它们只是被添加到列表的末尾一样,这是有道理的;但是,我不希望它看起来像这样;那我该怎么办?事实上,有什么方法可以子类化UIActionSheet
正确并使其工作?
您只需按照正确的顺序添加它们,然后设置cancelButtonIndex
and destructiveButtonIndex
手动。
对于您的代码示例:
if (self = [super initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTile:nil otherButtonTitles:nil]) {
if (firstButton) {
id buttonTitle;
int idx = 0;
va_list argList;
va_start(argList, firstButtton);
while (buttonTitle = va_arg(argList, id)) {
[self addButtonWithTitle:buttonTitle]
idx++;
}
va_end(argList);
[self addButtonWithTitle:cancel];
[self addButtonWithTitle:destroy];
self.cancelButtonIndex = idx++;
self.destructiveButtonIndex = idx++;
}
}
return self;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)