dismissViewControllerAnimated崩溃在ios5

由于循环引用,代码是否会崩溃?

MenuController: UIViewController - (id)initWithNibName: {... TabsController *tabs = [[TabsController alloc] initWithNibName:@"TabsController" bundle:nil]; self.tab = tabs; .... } //button pressed: - (IBAction)showPrefFromMenu:(id)sender { // todo change delegate!? tab.tabDelegate = self; [self presentModalViewController:tab animated:YES]; //[tab release]; } // delegate method: -(void)myViewDismissed { .... NSLog(@"tab references: %d", [tab retainCount]) ; [self dismissModalViewControllerAnimated:YES];//crash ... } 

模态/子类:

 TabsController : UIViewController <...> - (IBAction)dismissTabs:(id)sender { ... NSLog(@"dismissTabs: sender: %@",sender); [self.tabDelegate myViewDismissed]; } 

正如我所看到的self.tabDelegate是MenuController实例,并在该代码要做解雇和释放TabsController。

虽然在[self.tabDelegate myViewDismissed]之后没有更多的代码; 但是如果它会比不能执行,因为它被释放,也许程序集Ret或什么指令不能被执行? 返回声明。

我会尝试分离委托或任何更好的解决scheme?

编辑:崩溃是典型的:EXC_BAD_ACCESS(代码= 1,地址= 090)大会看起来像这样:ldr r1,[r4,r0]

编辑2:更改了一下代码,因为在模拟器4.3不会崩溃,但在5.0它是,现在这里是目前的代码:

 - (IBAction)showTab:(id)sender { tab.tabDelegate = self; if (SYSTEM_VERSION_LESS_THAN(@"5.0")) { [self presentModalViewController:tab animated:YES]; } else{ NSLog(@"Executing presentViewController (ios>= 5.0)"); [self presentViewController:tab animated:true completion: nil]; } } -(void)delegateCallback { if (SYSTEM_VERSION_LESS_THAN(@"5.0")) { [self dismissModalViewControllerAnimated:NO]; } else{ NSLog(@"Executing dismissViewControllerAnimated (ios>= 5.0)"); [self dismissViewControllerAnimated:TRUE completion: nil];//crash } } 

Edit3屏幕截图:

线程

UIWindowController转换:fromViewController:toViewController:didEndSeelctor行崩溃,原因是:没有parentViewController: https ://devforums.apple.com/message/451045这里的伙计们find了一个解决scheme: https : //github.com/ideashower/ShareKit/问题/ 254,但在NDA下

编辑解决了revut PushviewController为ios 5.0+一个heplfull链接: https ://stackoverflow.com/a/7767767/529543

 - (IBAction)presentViewController:(id)sender { tab.tabDelegate = self; if (SYSTEM_VERSION_LESS_THAN(@"5.0")) { [self presentModalViewController:tab animated:FALSE]; } else{ NSLog(@"Executing presentViewController (ios>= 5.0) [tab retainCount]: %d " ,[tab retainCount]); // store parent view to able to restore the state: parentView = self.view.superview; // init a navigation controler and set up: navigationController=[[UINavigationController alloc] initWithRootViewController:self]; [self.view removeFromSuperview]; [myAppDelegate.window addSubview:navigationController.view]; ///appDelegate is delegate of ur Application navigationController.navigationBar.hidden =true; [navigationController pushViewController:tab animated:YES]; } 

}

并popup:

 -(void)infoViewDismissed { if (SYSTEM_VERSION_LESS_THAN(@"5.0")) { [self dismissModalViewControllerAnimated:NO]; } else{ NSLog(@"Executing dismissViewControllerAnimated (ios>= 5.0) "); [navigationController popToRootViewControllerAnimated:false]; [navigationController.view removeFromSuperview]; [parentView addSubview:self.view]; } } 

我已经解决了我的问题,在一个非常丑陋的模式,但function…也告诉放弃对ios3的支持:)我不喜欢在运行时的GUI架构开关。

你的问题有点难以理解,但我认为你有一个保留周期:

 ObjectA retains ObjectB ObjectB retains ObjectA 

这两个对象都不被释放?

您的tabDelegate属性应为:

 @property (nonatomic, assign) id tabDelegate; // ^^^^^^-This is the important bit, this stops the retain cycle. 

很难告诉没有更多的信息(你是否使用ARC,你是否保留/分配委托,等等…),但每个iOS文档,你也使用不推荐的模态查看方法。 可能值得尝试:

 [self presentViewController:tab animated:YES completion:NULL]; 

 [self dismissViewControllerAnimated:YES completion:NULL];