我有一个表格视图,其中包含不同类型的表格视图单元格。在其中一个单元格中,有两个按钮,当按下时会加载一个视图控制器。我正在使用以下函数来处理按钮的按下:
- (IBAction)leftButtonPressed:(id)sender
{
// Getting the pressed button
UIButton *button = (UIButton*)sender;
// Getting the indexpath
NSIndexPath *indPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
// Loading the proper data from my datasource
NSArray *clickedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indPath.row];
[[SOEventManager sharedEventManager] setSelectedEvent:clickedEvent[0]];
// Everything working as it should up to this point
// Performing seque...
[self performSegueWithIdentifier:@"buttonSegue" sender:self];
}
我的buttonSegue应该推送一个新的视图控制器。但是它似乎不止推了一次,因此我收到以下警告:
2013-11-27 01:48:30.894 Self-Ordering App[2081:70b] nested push animation can result in corrupted navigation bar
2013-11-27 01:48:31.570 Self-Ordering App[2081:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
在我的情况下,这会导致应用程序崩溃,因为我想要弹出视图控制器并立即返回到表视图的事件。我使用一个警报视图来处理此事件,并使用以下代码处理:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
// ...
// Additional checking of button titles....
else if ([buttonTitle isEqualToString:NSLocalizedString(@"Vissza", nil)])
{
[self.navigationController popViewControllerAnimated:YES];
}
}
值得一提的是,我的“常规”表视图单元格还有另一个转换方式,在这种情况下,我使用了prepareForSegue:方法。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"detailSegue"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SOEvent *selectedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indexPath.row];
[[SOEventManager sharedEventManager] setSelectedEvent:selectedEvent];
}
}
在这种情况下,视图控制器会被完美地推送,并在需要时立即弹出。我正在iOS7和Xcode 5上进行测试。我以前没有遇到过这样的问题,非常感谢任何帮助。