我的 UIActionSheet 表现得像非模态?

发布于 2024-10-09 00:45:43 字数 476 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我喜欢麦丽素 2024-10-16 00:45:43

操作表不是模态的。 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:.

一袭白衣梦中忆 2024-10-16 00:45:43

确保标头中有 UIActionSheetDelegate

Make sure you have the UIActionSheetDelegate in your header.

拧巴小姐 2024-10-16 00:45:43

如果我想在用户不允许取消选项的情况下得到问题的答案,我会这样做(关键是:“if(buttonIndex == -1)performSelector”)...基本上只是循环直到满意...

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (debug==1) {
        NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
    }
    if (buttonIndex == -1) {
        [self performSelector:@selector(selectDb) withObject:nil afterDelay:0.1];
    } else {
        [DataLayer selectDatabase: buttonIndex];
    }
}

- (void) selectDb {
    if (![DataLayer hasSelectedDatabase]) {
        actionSheet  = [[UIActionSheet alloc] initWithTitle:@"Filter" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Main", @"Training", @"Test 1", @"Test 2", @"Test 3", @"Test 4", nil];
         [actionSheet showInView:[self view]];
   }
}

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...

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (debug==1) {
        NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
    }
    if (buttonIndex == -1) {
        [self performSelector:@selector(selectDb) withObject:nil afterDelay:0.1];
    } else {
        [DataLayer selectDatabase: buttonIndex];
    }
}

- (void) selectDb {
    if (![DataLayer hasSelectedDatabase]) {
        actionSheet  = [[UIActionSheet alloc] initWithTitle:@"Filter" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Main", @"Training", @"Test 1", @"Test 2", @"Test 3", @"Test 4", nil];
         [actionSheet showInView:[self view]];
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文