UIActionSheet 长列表行为在 4.2 中发生了变化?

发布于 2024-10-08 05:00:34 字数 1449 浏览 3 评论 0原文

我发现 iOS 4.2 中 UIActionSheet 的行为发生了一些变化。我在苹果的开发者文档或论坛中找不到任何相关内容,所以我不知道如何解决它。

在我的列表应用程序中,我向用户呈现一个操作表,她可以从中选择她想要在启动时加载的列表。显然,这意味着项目的数量是可变的,并且控件可以很好地处理它。直到大约 7 个项目,所有项目都显示为按钮。一旦超过该阈值,它就会将项目放入滚动视图中以供选择。在 4.2 之前,它在滚动列表中包含“取消”按钮。在 4.2 中,现在似乎分离了 Cancel 控件,将其保留为按钮,同时将其余项目放入滚动视图中。问题是,它似乎将 Cancel 项目保留在按钮索引列表中,因此当我检查 clickedButtonAtIndex: 或 didDismissWithButtonIndex: 中的 buttonTitleAtIndex:buttonIndex 时,第一个项目返回“Cancel”,然后其他项目标题为关闭 1。单击“取消”按钮也会返回“取消”。

其他人经历过这种情况并对如何处理有建议吗?同样,这在 3.0、3.1、4.0 和 4.1 中运行良好。

这是我正在使用的相关代码:

- (IBAction)popupDefaultListActionSheet {
    UIActionSheet *popup = [[UIActionSheet alloc]
        initWithTitle:nil
        delegate:self
        cancelButtonTitle:@"Cancel"
        destructiveButtonTitle:nil
        otherButtonTitles:nil];
   for (List *l in allActiveLists) { // allActiveLists defined elsewhere
    [popup addButtonWithTitle:[l label]];
   }
   popup.actionSheetStyle = UIActionSheetStyleBlackOpaque;
   popup.tag = 23;
   [popup becomeFirstResponder];
   [popup showInView:[self.view.window.subviews objectAtIndex:0]];
   [popup release];
 }

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

   DLOG(@"AppSettingsVC.actionSheet didDismissWithButtonIndex: %d", buttonIndex);
   NSString *defaultListName = [actionSheet buttonTitleAtIndex:buttonIndex];
   DLOG(@"chosen default list was: %@", defaultListName);
}

I am seeing some changed behavior in iOS 4.2 with UIActionSheet. I can't find anything in Apple's developer docs or forums about it, so I'm not sure how to resolve it.

In my list app, I present the user with an actionsheet from which she can pick the list she wants to load on startup. Obviously that means there will be a variable number of items, and the control handles it fine. Until about 7 items, it shows all items as buttons. Once it crosses that threshold, it puts the items into a scroll view to choose from. Until 4.2, it included the Cancel button in that scrolling list. In 4.2, it now seems to be separating the Cancel control, leaving it as a button while putting the rest of the items into the scroll view. The problem is that it appears that it keeps the Cancel item in the list of button indices, so that when I inspect the buttonTitleAtIndex:buttonIndex in either clickedButtonAtIndex: or didDismissWithButtonIndex:, the first item returns "Cancel", then the other item titles are off by 1. Clicking the Cancel button also returns "Cancel".

Anyone else experienced this and have a suggestion for how to handle it? Again, this worked fine in 3.0, 3.1, 4.0, and 4.1.

Here's the relevant code I'm using:

- (IBAction)popupDefaultListActionSheet {
    UIActionSheet *popup = [[UIActionSheet alloc]
        initWithTitle:nil
        delegate:self
        cancelButtonTitle:@"Cancel"
        destructiveButtonTitle:nil
        otherButtonTitles:nil];
   for (List *l in allActiveLists) { // allActiveLists defined elsewhere
    [popup addButtonWithTitle:[l label]];
   }
   popup.actionSheetStyle = UIActionSheetStyleBlackOpaque;
   popup.tag = 23;
   [popup becomeFirstResponder];
   [popup showInView:[self.view.window.subviews objectAtIndex:0]];
   [popup release];
 }

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

   DLOG(@"AppSettingsVC.actionSheet didDismissWithButtonIndex: %d", buttonIndex);
   NSString *defaultListName = [actionSheet buttonTitleAtIndex:buttonIndex];
   DLOG(@"chosen default list was: %@", defaultListName);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

吻风 2024-10-15 05:00:34

尝试在最后动态添加取消按钮,而不是最初设置它:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"My Action Sheet"
                                                         delegate:self
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

for (I32 i = 0; i < itemCount; i++) {
    [actionSheet addButtonWithTitle:itemText];
}

[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet setCancelButtonIndex:itemCount];

至少对我们来说在 iOS 4.2 中似乎可以正常工作。

Try adding the cancel button dynamically at the end instead of setting it up initially:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"My Action Sheet"
                                                         delegate:self
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

for (I32 i = 0; i < itemCount; i++) {
    [actionSheet addButtonWithTitle:itemText];
}

[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet setCancelButtonIndex:itemCount];

Seems to work correctly in iOS 4.2 for us at least.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文