使用pushViewController呈现新视图时收到崩溃

时间:2011-08-19 06:07:01

标签: iphone objective-c ios

我使用xcode 4.2新的ARC功能来开发一个新的应用程序,但我遇到了一个问题,pushViewController呈现一个新的视图。以下是我的代码:

QuestionVew *view = [[QuestionVew alloc] initWithStyle : UITableViewStyleGrouped];
[self.navigationController pushViewController : view animated : YES];

视图级别为:

BookView -> ChapterView -> SectionView -> QuestionVew.

所有这些都是UITableViewController。

当我快速切换这些视图时,发生了崩溃! 错误信息是:

-[UIViewAnimationState sendDelegateAnimationDidStop:finished:]:
message sent to deallocated instance 0x22b28f90

这种情况怎么了?我该如何解决?

谢谢!

----------新编辑--------

编辑后,我遇到了问题:

[UIViewAnimationState release]: message sent to deallocated instance 0x3ade8f90

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // do something
    QuestionVew *view = [[QuestionVew alloc] initWithStyle : UITableViewStyleGrouped];
    [self performSelector : @selector(showChildView:) withObject:view afterDelay:0.1];
 }

 - (void) showChildView : (UITableViewController *) aView {
    [self.navigationController pushViewController : aView animated : YES];
 }
[UIViewAnimationState release]: message sent to deallocated instance 0x3ade8f90

并且,我不能释放任何对象,因为ARC不被允许。

5 个答案:

答案 0 :(得分:0)

看看this question。如果你要一个接一个地快速呈现模态视图,你应该在两者之间添加一点延迟。所以,替换你的代码

[self.navigationController pushViewController : view animated : YES];

 [self performSelector:@selector(presentModal) withObject:nil afterDelay:0.1];

并添加方法

- (void) presentModal{
    [self presentModalViewController:view animated:YES];  
}

答案 1 :(得分:0)

viewDidUnload方法中,编写以下代码。

self.tableView.delegate = nil;
self.tableView.dataSource = nil;

答案 2 :(得分:0)

试试这种方式

[view setModalPresentationStyle:UIModalPresentationFullScreen];

[self presentModalViewController:view animated:YES];

阅读你的评论后。这是我能为您提供的解决方案

试试这个:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: view];

[view setModalPresentationStyle:UIModalPresentationFullScreen];

[self presentModalViewController:navController animated:YES];

//navController.navigationBarHidden = YES;

[navController release];

我使用这个逻辑来为不同的导航控制器维护单独的堆栈。它对我有用。

答案 3 :(得分:0)

告诉我,有一件事你甚至回来了,就像从一个问题到另一个书或某个视图一样弹出视图? 如果是这种情况那么它肯定会崩溃becoz所有的视图控制器都在堆栈中,当你同时弹出并推动它时,它会错过控制器的引用并且它会崩溃。我想你应该创建一个视图控制器数组并弹出到特殊阵列根据您的需要。

NSArray *array = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];

答案 4 :(得分:-1)

你已经发布了一些使用furthur的对象。如果你评论它,那么它可能不会崩溃。专注于发布。