我是Objective-C的新手,我尝试编写一个iPad应用程序(Objective-C2.0,Xcode4.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)。现在,我有一个简单的问题:为什么我的“取消”按钮没有出现?
发布于 2011-04-14 21:25:02
正如你的标签所暗示的,你可能正在做一个ipad项目。
文档介绍了iPads的cancel按钮:
cancelButtonTitle
取消按钮的标题。此按钮将自动添加到操作表中,并为其分配一个适当的索引,该索引可从cancelButtonIndex属性中获得。此按钮显示为黑色,表示它表示取消操作。如果不需要cancel按钮或要在iPad上显示动作单,请指定为nil。
您可以通过在操作表外部触摸来取消。
发布于 2011-04-14 21:26:11
您最有可能使用的是iPad,新的界面习惯用法是不显示cancel按钮。用户可以通过简单地在工作表外部单击来取消工作表。这不是最好的设计决策,但这就是现在的方式。
发布于 2013-01-28 21:52:15
在ipad上,它不显示取消按钮。因为ipad的宽度比iphone大&如果你不喜欢ipad,你可以在ipad的动作单之外加个标签。
详细说明:
查看这张显示ok按钮的iphone图片

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

单击时每个按钮的值(buttonIndex)如下:
➤删除消息-0
➤选项1-1
➤选项2-2
➤OK -3
在iPad上,当用户点击动作单之外的区域时,动作单被解除,buttonIndex的值变为3。有趣的是,如果您为cancelButtonTitle: part指定了nil,则当动作单被解除时,buttonIndex的值将为-1。
https://stackoverflow.com/questions/5663908
复制相似问题