我使用这个代码打开一个视图控制器
self.secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:self.secondViewController animated:YES];
[self.secondViewController release];但是,如果我在第二次调用此代码时使用[self.secondViewController release];,它会崩溃,因为
[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x18a890如果我不使用它,这一切都可以,但在这种情况下,我什么时候可以取消我的第二个视图控制器?你能帮帮我吗?
发布于 2012-01-20 17:50:36
根据您的代码(self.secondViewController),我的理解是,您已经将secondViewController声明为.h文件中的一个变量,而@synthesize则声明为您的.m文件中的一个变量。
if (self.secondViewController == nil) self.secondViewController = [SecondViewController alloc initWithNib:@"SecondViewController“bundle:nil];self ====self.secondViewController=[SecondViewController alloc initWithNib:@”SecondViewController“bundle:nil];
在您的- (void)dealloc方法中,我将添加[self.secondViewController release];,在- (void)viewDidUnload中添加[self setSecondViewController:nil];。
以上代码假设您是,而不是使用的。如果您正在使用ARC,我将修改我的代码如下:
instantiateViewControllerWithIdentifier:@"secondViewController";//
//不要在.h文件//中将secondViewController声明为变量,而是在情节提要中给它一个标识符,例如SecondViewController //和secondViewController *svc = self.storyboard自我演示显示视图控制器: svc动画:是;svc= nil;
https://stackoverflow.com/questions/8944583
复制相似问题