我的 UIActionSheet 表现得像非模态?
NSLog(@"Display Action Sheet");
UIActionSheet *alert = [[UIActionSheet alloc] initWithTitle:@"Warning" delegate:self cancelButtonTitle:@"Proceed" destructiveButtonTitle:@"Cancel (current data will be discard)" otherButtonTitles:nil];
[alert showInView:[self view]];
[alert release];
NSLog(@"Action Sheet Released");
这是我创建操作表的代码。在我看到操作表之前,“显示操作表”和“已发布操作表”都会输出到调试器控制台。实际上,我在收到用户输入后想要执行的其他代码都在我呈现操作表之前执行。
这是比较奇怪的。我想我可以使用操作表根据用户的输入执行代码。
NSLog(@"Display Action Sheet");
UIActionSheet *alert = [[UIActionSheet alloc] initWithTitle:@"Warning" delegate:self cancelButtonTitle:@"Proceed" destructiveButtonTitle:@"Cancel (current data will be discard)" otherButtonTitles:nil];
[alert showInView:[self view]];
[alert release];
NSLog(@"Action Sheet Released");
This is my code that creates an action sheet. Before I see the action sheet, both "Display Action Sheet" and "Action Sheet Released" get output to the debugger console. Actually other codes that I want to execute AFTER I receive input from user are all executed before I am presented the action sheet.
This is rather weird. I thought I could use action sheet to execute codes based on user's input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
操作表不是模态的。 iOS 中几乎没有什么。您需要使用
UIActionSheetDelegate
方法之一处理用户在工作表中选择的任何内容,例如-actionSheet:clickedButtonAtIndex:
。Action sheets aren't modal. Pretty much nothing in iOS is. You need to handle whatever the user chooses in the sheet in one of the
UIActionSheetDelegate
methods, like-actionSheet:clickedButtonAtIndex:
.确保标头中有
UIActionSheetDelegate
。Make sure you have the
UIActionSheetDelegate
in your header.如果我想在用户不允许取消选项的情况下得到问题的答案,我会这样做(关键是:“if(buttonIndex == -1)performSelector”)...基本上只是循环直到满意...
If I want the answer to a question without the user allowing the option of cancel, I do something like this (key is : "if (buttonIndex == -1) performSelector")... Basically just loop till happy...