在我的主视图中,我有4行静态表。其中2行深入到主视图中的详细视图,另2行替换详细视图的内容。我通过适当地调用showViewController()和showDetailViewController()函数来控制showViewController()方法发生了什么:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
Master2TVC *m2tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"master-2"];
[self showViewController:m2tvc sender:self];
} else if (indexPath.row == 1) {
Master3TVC *m3tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"master-3"];
[self showViewController:m3tvc sender:self];
} else if (indexPath.row == 2) {
Detail2VC *d2vc = [self.storyboard instantiateViewControllerWithIdentifier:@"detail-2"];
[self showDetailViewController:d2vc sender:self];
} else if (indexPath.row == 3) {
Detail3VC *d3vc = [self.storyboard instantiateViewControllerWithIdentifier:@"detail-3"];
[self showDetailViewController:d3vc sender:self];
}
}主细节模板创建从主视图到详细视图的引用:
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];如果我正确地理解了事物,那么这个引用就会存在,这样主端就可以向细节端发送消息。在我的示例中,详细视图的类将发生变化(Detail3VC、Detail2VC等),因此我决定移除这一行并以另一种方式进行消息传递;然而,现在,当我加载任何新的详细视图并更改iPad的旋转时,应用程序有时会与错误EXC_BAD_ACCESS一起崩溃。
据我所知,EXC_BAD_ACCESS通常意味着有一个不应该挂在某处的对象。我一直无法在苹果文档中找到任何关于在使用showDetailViewController()调用时必须更改其他任何内容的内容。实际上,我认为使用showDetailViewController()的原因是splitViewController可以管理所有细节,而不必在自己的类中使用。
有人能看到这里的错误吗?
发布于 2015-01-05 05:49:22
我已经确认了你遇到的坠机。它总是,而不是有时,发生在改变iPad的旋转。
无论如何,我们似乎需要实现-targetDisplayModeForActionInSplitViewController: of UISplitViewControllerDelegate并返回除UISplitViewControllerDisplayModeAutomatic之外的任何值。
- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc {
return UISplitViewControllerDisplayModePrimaryOverlay;
}https://stackoverflow.com/questions/27736335
复制相似问题