【发布时间】:2010-12-19 17:28:07
【问题描述】:
我看到 iOS 4.2 中带有 UIActionSheet 的行为发生了一些变化。我在 Apple 的开发者文档或论坛中找不到任何相关内容,因此我不确定如何解决。
在我的列表应用程序中,我向用户展示了一个操作表,她可以从中选择她想要在启动时加载的列表。显然,这意味着会有可变数量的项目,并且控件可以很好地处理它。直到大约 7 个项目,它将所有项目显示为按钮。一旦超过该阈值,它就会将项目放入滚动视图中以供选择。在 4.2 之前,它在该滚动列表中包含“取消”按钮。在 4.2 中,它现在似乎正在分离 Cancel 控件,将其保留为按钮,同时将其余项目放入滚动视图。问题是它似乎将取消项目保留在按钮索引列表中,因此当我检查 clickedButtonAtIndex: 或 didDismissWithButtonIndex: 中的 buttonTitleAtIndex:buttonIndex 时,第一个项目返回“取消”,然后其他项目标题是off by 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);
}
【问题讨论】:
-
我忘了说,当其他ButtonTitles 被提供时似乎很好。所以它必须与 addButtonWithTitle: 的工作原理有关。
标签: iphone uiactionsheet