开发者

popToViewController raises "Assertion failure" message, how to solve it?

In CoreData, I have the data graph with some entities, and each object is populated in a view controller, at a defined screen, I want to pop out some (>1) objects to return to a define screen.

I tried to pop the view controllers out of the navigation stack with these lines of code:

ObjectA *objectA = objectD.objectC.objectA;
NSLog(@"objectA name: %@", objectA.name);
MyViewController    *controller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil withObjectA:objectA];
[self.navigationController popToViewController:controller animated:YES];
[controller release];

The objectA, objectB, objectC, objectD are all objects from my data graph(with the inverse relationship, I can query back the objectA from the objectD through objectC)

The following error message is raised:

Assertion failure in -[UINavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-984.38/UINavigationController.m:1807

There are two questions here:

  • If开发者_StackOverflow中文版 the two objects are different, how comes they have the same name? the inverse relationship can not get back the objectA in which I used to initialize MyViewController?
  • How do you normally do popToViewController? How can I implement save/load the current state of my navigation controller so that when the application quits, I can reload the navigation controller? What are the best practices?


This has nothing to do with Core Data. You are creating a new view controller when you should just reference your existing MyViewController instance. The newly created controller is obviously not on the navigation controller's stack and so you get an exception when you try to switch to it.

Use the self.navigationController.viewControllers array to reference the controller that's already on the nav controller's stack.


popToViewController: can only take you back to an existing ViewController that's already on the UINavigationController's stack. You're allocating a completely new controller and then trying to pop to it.

The Core Data object graph of your model objects isn't directly relevant here; all popToViewController: is dealing with is the stack of ViewController objects.

To pop to a specific ViewController, you need a reference to that ViewController object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜