IOS 7新特性--UIActionSheet

117 篇文章 0 订阅

今天在研究UIActionSheet   IOS7新特性时,当时也不知道脑子怎么回事,直接把代码放到viewDidLoad中来执行,费了半天的劲总是出现问题,也怀疑过是不是xcode5的问题,把UIActionSheet这小段代码发给朋友,说没有问题,很郁闷 。后来想起自己平时用都是放到一个button的方法里来操作,于是有个观点产生UIActionSheet必须配合动作时才有效果。于是去查看开发文档,上面有句话也验证了观点:Action sheets display a set of buttons representing several alternative choices to complete a task initiated by the user.

官方文档:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UIActionSheet.html


生活就是这样,总会出现个小问题。IOS7下的UIActionSheet在方法上没有改变。常用方法还是

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;

代码如下 :

UIActionSheet *actionSheet = [[UIActionSheetalloc]initWithTitle:@"Fuck-IOS7"

                                                      delegate:self

                                             cancelButtonTitle:@"取消"

                                        destructiveButtonTitle:nil

                                             otherButtonTitles:@"让你气死我了",@"让你气死他了",@"让你气死我们了",nil];

    actionSheet.actionSheetStyle =UIActionSheetStyleAutomatic;

   // [actionSheet showInView:[UIApplication sharedApplication].keyWindow];

    [actionSheet showInView:self.view];

xcode5在新建工程时,内存释放是自动释放,所以这里就不用写[actionSheetrelease];方法了。如果想设置成非自动release,方法如下图:


效果图如下:



现在把出现的问题贴下:Sheet can not be presented because the view is not in a window,顺便在stackoverflow上找了答案,希望能给大家带来帮助,在此感谢我的朋友们。

1.

UIWindow* window = [[UIApplication sharedApplication] keyWindow];
if ([window.subviews containsObject:self.view]) {
    [emailSheet showInView:self.view];
} else {
    [emailSheet showInView:window];
}
2.
[actionSheet showInView:[[[[UIApplication sharedApplication] keyWindow] subviews] lastObject]];
参考:http://stackoverflow.com/questions/18932544/nsinvalidargumentexception-reason-sheet-can-not-be-presented-because-the-vi

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值