【问题标题】:Issue in UIActionSheet on iPad. Can press any button when it's showingiPad 上的 UIActionSheet 中的问题。显示时可以按任意按钮
【发布时间】:2014-11-08 17:59:12
【问题描述】:

我在 iPad 视图上的 UIActionSheet 遇到问题。我真的不知道为什么我可以在当前视图处于活动状态时按下任何可用的按钮。

示例:按下 BarButtonItem。 UIActionSheet 看起来像一个弹出框,同时它显示您可以按 Back BarButtonItem。

有什么办法可以避免这种情况吗?我在 iPhone 视图上试过了,效果很好。

【问题讨论】:

  • 你能把你的代码贴在这里吗?
  • @Ganesh,典型的初始化操作表然后[action showFromBarButtonItem:sender animated:YES];
  • 在回答中发布了我的代码,请查看。
  • 嘿@Ganesh,谢谢。我回家后会检查一下。 :) 谢谢。只是想知道为什么你仍然做@sythesize 的事情?我相信我们已经有了从 xCode 4.4 开始的自动属性合成。
  • 当我们创建一个属性时,我们必须实现 @synthesize 并检查此链接以供参考。useyourloaf.com/blog/2012/08/01/…

标签: ios ipad ios7


【解决方案1】:

试试这样。 首先创建一个属性

@property (weak, nonatomic) UIActionSheet *actionSheet;
@synthesize actionSheet = _actionSheet;

在那个按钮动作之后

- (IBAction)clickActionSheet:(UIBarButtonItem *)sender {
if (self.actionSheet) {
    // do nothing
} else {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action sheet demo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Do something else" otherButtonTitles:DO_SOMETHING_ELSE, nil];
[actionSheet showFromBarButtonItem:sender animated:YES];
}   
}

实现这个 UIActionSheetDelegate

  -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex(NSInteger)buttonIndex
{
NSString *choice = [actionSheet buttonTitleAtIndex:buttonIndex];
if (buttonIndex == [actionSheet destructiveButtonIndex]) {
    // destroy something
    NSLog(@"Destroy");
} else if ([choice isEqualToString:DO_SOMETHING_ELSE]){
    // do something else
    NSLog(@"Do something else");
}
}

【讨论】:

  • 不知何故。这就是我的代码实际上看起来很相似的地方,除了我只是想知道为什么需要为 UIActionSheet@Synthesize 设置属性?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-19
  • 1970-01-01
  • 1970-01-01
  • 2013-11-01
  • 1970-01-01
  • 2013-07-29
  • 2012-08-27
相关资源
最近更新 更多