【问题标题】:Strange behavior of Cancel button's ActionSheet取消按钮的 ActionSheet 的奇怪行为
【发布时间】:2011-04-14 13:21:05
【问题描述】:

我是 Objective-C 的新手,我尝试编写一个 iPad 应用程序(Objective-C 2.0,Xcode 4.0.1)。 我“玩”了 ActionSheet 以了解它是如何工作的。在一个 nib 文件中,我放置了一个绑定到我的“buttonPressed”方法的按钮。

我已经写了这段代码:

-(IBAction)buttonPressed
{   
    UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"My Action Sheet" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"OK" otherButtonTitles:@"Test", nil];

    NSLog([NSString stringWithFormat:@"%d", [myActionSheet numberOfButtons]]);
    NSLog([myActionSheet buttonTitleAtIndex:0]);
    NSLog([myActionSheet buttonTitleAtIndex:1]);
    NSLog([myActionSheet buttonTitleAtIndex:2]);

    [myActionSheet showInView:self.view];
    [myActionSheet release];
}

这是 NSLog 结果:

2011-04-14 14:52:30.428 TrampManage[3568:207] 3
2011-04-14 14:52:30.429 TrampManage[3568:207] OK
2011-04-14 14:52:30.430 TrampManage[3568:207] Test
2011-04-14 14:52:30.432 TrampManage[3568:207] Cancel

但显示的视图却完全不同(参见图片:http://www.imagup.com/data/1117452257.html)。目前,我有一个简单的问题:为什么我的“取消”按钮没有出现?

【问题讨论】:

标签: objective-c ipad xcode4


【解决方案1】:

正如您的标签所暗示的,您可能正在从事 ipad 项目。

文档中提到了 iPad 的取消按钮:

cancelButtonTitle 取消按钮。这个按钮被添加到 动作表自动和 分配了适当的索引,该索引 可从 取消按钮索引属性。这 按钮显示为黑色 表示它代表取消 行动。 如果你不想指定 nil 取消按钮或正在显示 iPad 上的操作表

您可以通过触摸操作表外部来取消。

【讨论】:

  • 感谢您的快速回答。我已经阅读了 ActionSheet 参考文档,您的绕过建议很有趣,但是......如果我想要一个 CancelButton 怎么办?
  • 使用其他按钮,但你必须忍受浅色背景。
【解决方案2】:

您很可能在 iPad 上,新界面习惯用法是不显示取消按钮。用户可以通过简单地在工作表外部单击来取消工作表。恕我直言,这不是最好的设计决策,但现在就是这样。

【讨论】:

    【解决方案3】:

    在 ipad 上它不显示取消按钮。因为 ipad 的宽度比 iphone 大,如果要关闭它,您可以在 ipad 上的操作表之外使用标签。

    详细说明:

    查看显示 ok 按钮的 iphone 图像

    下图显示了在 iPad 上显示时的操作表。 有趣的是,在 iPad 上的 OK 按钮(由 cancelButtonTitle: 参数)不显示。

    每个按钮被点击时的值(buttonIndex)如下:
    ➤ 删除消息 — 0
    ➤ 选项 1 — 1
    ➤ 选项 2 — 2
    ➤ 确定 — 3
    在 iPad 上,当用户点击 行动表,行动表被解雇,价值 buttonIndex 变为 3。有趣的是,如果您为 cancelButtonTitle: 部分,buttonIndex 的值将是 –1 当 操作表已关闭。

    【讨论】:

      猜你喜欢
      • 2010-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多