我正在使用actionSheet传递的actionSheet变量:didDismissWithButtonIndex:将调用的actionSheet与我班级中的UIActionSheet变量列表进行比较。这似乎是委托方法旨在区分事件的方式。
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (actionSheet == actionSheet1) {
switch (buttonIndex) {
case 0:
// Do Something
break;
case 1:
// Do Something Else
break;
case 2:
// Cancel
break;
}
}
if (actionSheet == actionSheet2) {
switch (buttonIndex) {
case 0:
// Do Something
break;
case 1:
// Do Something Else
break;
case 2:
// Cancel
break;
}
}
}
每次显示UIActionSheet时,我都会将一个UIActionSheet实例分配给其中一个类变量,设置显示属性,显示它并释放它。
起初工作顺利。问题是在运行一段时间后,最终两个UIActionSheet指针(上面的代码示例中的类变量actionSheet1& actionSheet2)将最终指向同一个内存,具体取决于运行时发生的情况,从而导致两个if语句委托方法来评估真实。不好。
现在,如果我每次运行只分配一次UIActionSheet并保留内存(从不调用release),这不应该发生。但我想在这里保守。 Apple是否打算以这种方式使用该代表?
答案 0 :(得分:6)
创建UIActionSheet时,请为其添加标记:
actionSheet.tag = 1; // or 2 or 3 or ...
然后,在您的委托方法中,根据标记切换以确定该特定工作表的行为。