看来我在 navigationController PushViewController 方法中发现了一个错误。为了重新创建它,我采用了示例主详细信息项目并对-didSelectRow:
method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController* view = [self.storyboard instantiateViewControllerWithIdentifier: @"view"];
NSDate *object = _objects[indexPath.row];
[view setDetailItem:object];
[self.detailViewController.navigationController pushViewController:view animated:YES];
}
我还将详细视图的情节提要 ID 更改为“视图”。发生的情况如下:
When selecting any of master's rows slowly (when the push animation has finished) it works fine:
If you select any of the rows while the animation is still showing, the detail view becomes inactive (shows the last row that was called with the push method before the bug) and only the navigation bar shows the push animation of a new view:
发生这种情况时,您会在调试器输出中收到一些警告:
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
nested push animation can result in corrupted navigation bar
Unbalanced calls to begin/end appearance transitions for <DetailViewController: 0x8a6e070>.
这是令人讨厌的部分:如果您返回详细信息视图的导航栏,然后在主视图的表格视图中选择不同的行,或者在详细信息中返回两次,应用程序将崩溃
Can't add self as subview
但是,如果您在 ios6 上运行相同的代码,它可以正常工作,不会出现任何问题或警告。
目前的解决方案:
使用animated:NO调用该方法似乎没有任何问题,显然没有推送动画。
另一种解决方案是在 Master 中设置一个布尔值,在调用 Push 方法时将其设置为 false,并在 Detail 的 viewDidAppear 中将其设置为 true。这样你就可以在调用push方法时检查该值。缺点:如果您尝试快速选择同一行,则 tableView 可能会出现滞后,如果您快速选择不同的行,那么它不会显示在详细信息中,但它将在主 tableview 中被选中并突出显示,您可以保存所选行的索引并更改代码中的选择,但这会导致行突出显示闪烁。
这两种解决方案都涉及一些妥协,所以我想找到另一种方法来处理这个问题。还有更好的解决方案吗?