gpt4 book ai didi

objective-c - ios5 上的dismissViewControllerAnimated 崩溃

转载 作者:行者123 更新时间:2023-12-01 18:27:47 29 4
gpt4 key购买 nike

代码会因为循环引用而崩溃吗?

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 或者什么指令不能执行?返回声明。

我会尝试将代表分开还是有更好的解决方案?

编辑:
崩溃是典型的:EXC_BAD_ACCESS(code=1,address=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截图:

threads

UIWindowController transition:fromViewController:toViewController:didEndSeelctor 行崩溃,原因是:没有 parentViewController:
https://devforums.apple.com/message/451045
伙计们在这里找到了解决方案: https://github.com/ideashower/ShareKit/issues/254但在 NDA 下

编辑已解决以重新写入 PushviewController for ios 5.0+
一个完整的链接: 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];

}

}

和弹出:
-(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];

}
}

我已经解决了我的问题,在一个非常丑陋的模式下,但功能......还被告知放弃对 ios3 的支持 :) 我根本不喜欢运行时的 GUI 架构切换。

最佳答案

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

ObjectA retains ObjectB
ObjectB retains ObjectA

并且两个对象都没有被释放?

您的 tabDelegate 属性应为:
@property (nonatomic, assign) id tabDelegate;
// ^^^^^^-This is the important bit, this stops the retain cycle.

关于objective-c - ios5 上的dismissViewControllerAnimated 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11832981/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com