我有一些使用新 UIAlertController 类的代码,这些代码在 iOS 8 中运行得很好。现在它在 iOS 9 中崩溃,并显示以下错误消息:
2015-07-23 10:38:27.499 MyApp[828:563509] -[UITabBarItem _viewForPresenting]: unrecognized selector sent to instance 0x157644960
2015-07-23 10:38:27.500 MyApp[828:563509] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarItem _viewForPresenting]: unrecognized selector sent to instance 0x157644960'
Run Code Online (Sandbox Code Playgroud)
问题似乎是使用 barButtonItem 字段来配置 popoverPresentationController,而不是仅仅使用 sourceView/sourceRect 东西。如果我切换到后者,那就没问题(但是当然,操作表不会从我希望它弹出的位置弹出)。到目前为止,谷歌搜索错误消息显示为空白。
这是代码。这是非常基本的,这里没有什么特别的:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"What do you want to do?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alertController addAction:[UIAlertAction actionWithTitle:@"Clear Call History" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
[self confirmClearCallHistory];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}]];
[alertController setModalPresentationStyle:UIModalPresentationPopover];
//if I do this (like I want to), it crashes:
[alertController popoverPresentationController].barButtonItem = self.tabBarController.callsTab;
// if I do this, it's fine:
// [alertController popoverPresentationController].sourceView = self.editButton;
// [alertController popoverPresentationController].sourceRect = self.editButton.bounds;
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
还有其他人有类似的问题吗?到目前为止,所有三个 iOS 9 测试版都是一样的......
(哦,我应该提到它只在 iPad 上崩溃,而不是在 iPhone 上......但这并不奇怪,因为操作表的演示模式在 iPhone 上是无操作的,即所有操作表都以相同的方式呈现有什么关系)
哦,有趣。我实际上将 UITabBarItem 实例传递到 barButtonItem 字段中。(我继承了旧代码,所以我没有意识到这一点)不知何故,这实际上在 iOS 8 上有效?去搞清楚。
所以是的,我想不能这样做。呵呵。
| 归档时间: |
|
| 查看次数: |
2050 次 |
| 最近记录: |