简体   繁体   中英

Three20: loadView and viewDidLoad not called when restoring through TTNavigator

When using the the Three20 framework I have a problem with the way how TTNavigator seems to work. If in applicationDidFinishLaunching I restore the previous state of the app with:

TTNavigator* navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
navigator.window = self.window;
[navigator restoreViewControllers];

The methods loadView and viewDidLoad of the ViewController that was just restored never get called. How can that be so?

Is that a bug or by design?

If it's by design, what would be a good fix. My problem is that I want the ViewController to load its nib. I've seen other workarounds, but they are ugly and have outside component (like the app delegate instead of the view controller itself) load the nib, which I would like to avoid. An example of those ugly workarounds is given in the TTNibDemo example that ships with the Three20 source code.

It depends in what way you are calling viewController, try in viewWillAppear, should work.

Are you testing on device?

navigator.window = self.window; _ [navigator restoreViewControllers];

On the device the first screen is always the first screen, whereas on the simulator that is not the case, and you should always check before with the condition

if(![navigator restoreViewControllers])
  // do this
else 
  TTNavigationController* navi = [[((MyViewController1*)[navigator topViewController]) viewControllers] objectAtIndex:0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM