一个View Controller中有多个UIActionSheets

时间:2011-02-24 07:27:45

标签: iphone cocoa-touch uiactionsheet

如果只有一个UIActionSheet方法,多个UIViewController如何添加到单个-actionSheet:clickedButtonAtIndex:

3 个答案:

答案 0 :(得分:7)

为您的操作表设置名称或标签,并执行类似这样的操作

  -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
 {
   if(actionSheet==yourActionsheet1)
     {
      //your logic
       }
     if(actionSheet==yourActionsheet2)
     {
      //your logic
       }
    }

希望这个帮助

答案 1 :(得分:3)

您可以创建多个操作表,如下所示:

actionSheet1 = [[UIActionSheet alloc] initWithTitle:@"Where to go"
                                                   delegate:self
                                          cancelButtonTitle:@"cancel"
                                     destructiveButtonTitle:@"Store 2"
                                          otherButtonTitles:@"Store 3",@"Store 4",@"Store 5",@"View Store Profile",nil];
 actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Where to go"
                                                   delegate:self
                                          cancelButtonTitle:@"cancel"
                                     destructiveButtonTitle:@"Store 1"
                                          otherButtonTitles:@"Store 3",@"Store 4",@"Store 5",@"View Store Profile",nil];
actionSheet3 = [[UIActionSheet alloc] initWithTitle:@"Where to go"
                                                   delegate:self
                                          cancelButtonTitle:@"cancel"
                                     destructiveButtonTitle:@"Store 1"
                                          otherButtonTitles:@"Store 2",@"Store 4",@"Store 5",@"View Store Profile",nil];

&安培;之后,请确定调用哪个操作表 - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

if(actionSheet==actionSheet1)
{
}
else if(actionSheet==actionSheet2)
{
}
else if(actionSheet==actionSheet3)
{
}

答案 2 :(得分:2)

您可以将多个操作表添加到同一个视图控制器。您可以为每个操作表设置标记,并检查委托方法中的标记以执行必要的功能。