显示UIActionSheet对象时,调用self出现的警告

编程实现一个Action Sheet: 在XXXViewController.m 中通过执行代码


UIActionSheet* actionSheet = [[UIActionSheetallocinitWithTitle:@"Are you sure?"delegate:selfcancelButtonTitle:@"No Way!"destructiveButtonTitle:@"Yes, I'm sure"otherButtonTitles:nil];

创建一个UIActionSheet对象。参数delegate为self为的是让ViewController响应用户交户信息,调用方法actionSheet: didDismissWithButtonIndex:。编译后运行成功。但始终在delegate:self上有类型不匹配的警告:Sending 'XXXViewController*' to parameter of incompatible type 'id<UIActionSheetDelegate>'。
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:方法原型如下:
- (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString*)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

[font=]所以貌似我不能把XXXViewController*类型的self当作参数传进去。如果消除这个警告是不是应该获得我这应用程序的delegate传进去?怎么获得这个正确的delegate呢?


解决:

你在XXXViewController后面加上<UIActionSheetDelegate>就可以了,在头文件的XXXViewController后面
@interface XXXViewController : UIViewController <UIActionSheetDelegate>,看看还有吗?


果然是这个问题啊!感谢!
UIActionSheetDelegate定义了实现UIActionSheet对象的方法。这个delegate实现了按钮和其他自定义操作。
如果要为按钮增设UIActionSheet操作,那么就要实现一个遵守此协议的delegate,作为响应actionsheet的委派。
如果在actionsheet中添加了按钮,就还要必须实现 actionSheet:clickedButtonAtIndex: 方法响应按钮按下动作,否则按钮按下就什么也不做。
另外还可以实现 actionSheetCancel:方法处理点击actionsheet取消按钮的情况。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值