从viewDidAppear调用presentViewController会导致ViewController泄露

时间:2014-09-05 17:15:33

标签: ios objective-c ios7

我有三个UIViewController派生类实例A,B,C

答:是一个带有单个按钮的视图,该按钮链接到buttonPressed和以下非标准代码

-(IBAction)buttonPressed {
    B = new local object of class B code left out for brevity
    B.dismissDelegate = self;
    [self presentViewController:B
                       animated:NO
                     completion:nil];
}
- (void)dismiss {
    [self dismissViewControllerAnimated:NO completion:nil];
}

B:是一个包含以下非标准代码的视图

- (void)viewDidAppear {
    C = new local object of class C code left out for brevity
    C.dismissDelegate = self;
    [self presentViewController:C
                       animated:NO
                     completion:nil];       
}
- (void)dismiss {
    [self.dismissDelegate dismiss];
}

C:是一个链接到buttonPressed

的视图
-(IBAction)buttonPressed {
    [self.dismissDelegate dismiss];
}

按下A上的按钮然后按下C上的按钮会导致分配多个C副本,这些副本从未被释放。但是,如果删除B并且A只启动C,则释放C的副本。

ARC已开启。

0 个答案:

没有答案