【问题标题】:UIAlertView without Cancel Button?没有取消按钮的 UIAlertView?
【发布时间】:2011-11-07 04:47:24
【问题描述】:

我正在尝试创建一个具有 3 个选项且没有“取消”按钮的 UIAlertView,但是当我这样做时,它总是将“按钮 3”设置为取消按钮。有什么办法可以避免吗?

UIAlertView *alertView= [[UIAlertView alloc] initWithTitle:@"Select One" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Button 1",@"Button 2", @"Button3", nil];

【问题讨论】:

  • 从文档来看,似乎没有什么令人惊讶的方法。我还在玩它,但取消按钮似乎默认为其他按钮之一。
  • 此时我已经完成了操作表。不是我想要的方式,所以如果有人知道如何使警报视图工作,请随时加入。

标签: iphone button uialertview cancel-button


【解决方案1】:

我的做法不同,将cancelButtonTitle 参数作为nil 传递。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
                           message:@"Message here"
                           delegate:self
                           cancelButtonTitle:nil
                           otherButtonTitles:@"OK", nil];

【讨论】:

    【解决方案2】:

    This 是一篇关于如何更改取消按钮位置的帖子。另外,如果UIAlertView 中只有 1 个按钮,则设置:

    _alertView.cancelButtonIndex = -1;
    

    将使按钮显示为非取消类型的按钮。据我所知,一旦你有多个按钮,UIAlertView 会强制最后一个按钮成为取消按钮。查看reference 可能会为您提供有关如何设置属性以实现此目的的线索,但我不太确定。希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      相关资源
      最近更新 更多