首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目标C: AlertView不工作

目标C: AlertView不工作
EN

Stack Overflow用户
提问于 2011-04-05 13:22:41
回答 2查看 432关注 0票数 1

在用户单击操作表中的“destructButton”之后,我实现了一个警报视图。代码片段如下:

代码语言:javascript
复制
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
  if (buttonIndex != actionSheet.cancelButtonIndex)
  {
     UIAlertView *alert = [[UIAlertView alloc] 
     initWithTitle:@"Something happened!"
     message:nil
     delegate:nil
     cancelButtonTitle:@"Phew!"
     otherButtonTitles:nil];
  }

  [alert show];
  [alert release];
}

我已经在.h文件中包含了UIActionSheetDelegate协议

代码语言:javascript
复制
@interface Control_FunViewController : UIViewController <UIActionSheetDelegate> {
    UITextField *nameField;
    UITextField *numberField;
    UILabel *sliderLabel;
    UISwitch *leftSwitch;
    UISwitch *rightSwitch;
    UIButton *doSomethingButton;

}

但是,当我单击操作表中的destructButton时,什么也没有发生。我是不是漏掉了什么?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-05 13:42:23

您的代表需要实现 actionSheet:clickedButtonAtIndex:**.**

行动说明书将在actionSheet:clickedButtonAtIndex:之后解散,之后代表将收到actionSheet:didDismissWithButtonIndex:

来自Apple Action Sheet Delegate Protocol reference

...代理必须实现actionSheet:clickedButtonAtIndex:消息,以便在单击这些按钮时进行响应;否则,您的自定义按钮什么也不做。在调用actionSheet:clickedButtonAtIndex:委托方法后,操作表将自动关闭。

您可以查看使用UIActionSheet的示例项目,如GenericKeychain

代码语言:javascript
复制
    // Action sheet delegate method.
    -      (void)actionSheet:(UIActionSheet *)actionSheet
        clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        // the user clicked one of the OK/Cancel buttons
        if (buttonIndex == 0)
        {
            [passwordItem resetKeychainItem];
            [accountNumberItem resetKeychainItem];
            [self.tableView reloadData];
        }
    }
票数 2
EN

Stack Overflow用户

发布于 2011-04-05 18:10:40

您已在.h文件上添加了UIActionSheetDelegate。这不仅仅是足够的。您还必须为UIActionSheet对象设置委托。请参阅下面的编码:

-(空)showActionSheet{ UIActionSheet *showActionSheet =[UIActionSheet allocinitWithTitle:@"dsfs“委托:自取消按钮标题:@”First Btn“destructiveButtonTitle:@"Dest Btn”otherButtonTitles:nil];action showInView:self.view;

}

在代码中,我将UIActionSheet委托设置为self,如果您在ViewController (Control_FunViewController)上添加了此方法,则此方法有效。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5547561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档