有没有办法避免在每个segue之后调用viewDidLoad?

Jon*_*han 2 iphone storyboard viewdidload segue

我在我的主ViewController中初始化表,数据等.对于更多设置,我想调用另一个Viewcontroller:

 DateChangeController *theController = [self.storyboard instantiateViewControllerWithIdentifier:@"dateChangeController"];
[self presentViewController:theController animated:YES completion:^{NSLog(@"View controller presented.");}];
Run Code Online (Sandbox Code Playgroud)

然后一些点击我返回一个segue(自定义:)

NSLog(@"Scroll to Ticket");
[self.sourceViewController presentModalViewController:self.destinationViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)

我的问题:

在返回到我的主ViewController之后,调用了viewDidLoad(每次).我读到,ARC在"转到"另一个ViewController并调用viewDidUnload方法后释放我的mainView,但是我想保留我的所有数据和表格一开始..

有解决方案吗 非常感谢你!

mat*_*att 5

问题是你这样做:

main view controller ->
    date change controller ->
        a *different* main view controller
Run Code Online (Sandbox Code Playgroud)

换句话说,虽然在你的口头描述中你使用了"返回我的主ViewController"这个词,但你实际上并没有回归 ; 你每次都要前进到这个主视图控制器的另一个实例,将所有这些视图控制器堆叠在一起.

返回现有视图控制器的方法不是制作segue而是返回!归来presentViewControllerdismissViewController.你没有使用segue; 你打电话dismissViewController.(好吧,在iOS 6中,你实际上可以使用segue,但它是一种非常特殊且相当复杂的segue,称为Unwind或Exit segue.)

如果你这样做,你会回到你原来的视图控制器,它一直坐在那里等待你的回归,并且viewDidLoad不会被调用.

所以,这对你来说是一个很好的问题,因为双重调用viewDidLoad是你的体系结构错误的标志.