我的一个观点使用了 3 个动作表,这些动作表是在单击各种按钮时产生的。由于我只有一种- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
方法,知道我正在处理哪个操作表的最佳方法是什么?选择我的任何 actionSheet 上的第一个按钮将是 buttonIndex 0。所以我需要知道如何知道来自哪个 actionSheet 调用。
想法?
我的一个观点使用了 3 个动作表,这些动作表是在单击各种按钮时产生的。由于我只有一种- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
方法,知道我正在处理哪个操作表的最佳方法是什么?选择我的任何 actionSheet 上的第一个按钮将是 buttonIndex 0。所以我需要知道如何知道来自哪个 actionSheet 调用。
想法?
您需要在创建操作表时设置标记并在操作表方法中对其进行测试。
我遇到了同样的问题,我只是根据操作表的标题设置了一个条件:
在
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (actionSheet.title == @"present action sheet A") {
//do some stuff
}
if (actionSheet.title == @"present action sheet B") {
//do some stuff
}
像魅力一样工作,不确定操作表是否有标签,但也许我错了。
对 3 个操作表使用类级别变量。然后你可以在actionSheet方法中比较action的来源。
创建操作时设置标签
UIActionSheet * actionSheet =
[[UIActionSheet alloc]
initWithTitle:@"My title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Option1",@"Option2", nil];
actionSheet.tag = 1100;
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(actionSheet.tag == 1100)
{
switch (buttonIndex)
{
case 0:
{
}
break;
case 1:
{
}
break;
default:
break;
}
}
}