Comrades,

I have a bunch of UITableViewControllers in my app, each of which is responsible for some aspect of the data in my sqlite database. Now, maybe I should have done it differently, but I am passing a backpointer from each "parent" vc to its "child" vc, where the child vc is going to allow updating the database in an appropriate manner and inform its parent vc of the change so that the data can be reloaded. I explicitly set the backpointer like this:

- (void) addProject {
        NSLog(@"ProjectsViewController:addProject button pressed");
        // create a project editor view with text fields in it
ProjectEditorViewController *projEd = [[ProjectEditorViewController alloc] initWithNibName: @"ProjectEditorView" bundle: nil];
        [projEd setParentViewController:self];  // setting my backpointer
        [self.navigationController pushViewController:projEd animated:YES];
}

and the ProjectEditorViewController has this implementation:

-(void) setParentViewController:(ProjectsViewController*) viewController {
        parentVC = viewController;
}

And later I can use that pointer to update the database and request a reloadData.

Seems simple enough, eh? (Maybe in a future post I will ask how I could have handled data synchronization better, but it seems like a long story just now.)



But I end up in setParentViewController TWICE during the addProject method, and the second time through the type of the argument is wrong. The first time its a ProjectEditorViewController (correct), but the second time its a UINavigationController (WTF?). This causes a crash later when I try to send a updateDatabase/reloadData message to the parentVC and the parentVC is the wrong type!




Tracing through addProject in the debugger, where I set my backpointer, and where I think all my trouble begins:

- (void) addProject {
        NSLog(@"ProjectsViewController:addProject button pressed");
        // create a project editor view with text fields in it
ProjectEditorViewController *projEd = [[ProjectEditorViewController alloc] initWithNibName: @"ProjectEditorView" bundle: nil];
<bp>      [projEd setParentViewController:self];  // setting my backpointer

<step>
>>> at this point, the first time I step into addProject the callstack looks like this: #0 0x00007f47 in -[ProjectEditorViewController setParentViewController:] at ProjectEditorViewController.m:33 #1 0x00003d2b in -[ProjectsViewController addProject] at ProjectsViewController.m:74


<step>
        [self.navigationController pushViewController:projEd animated:YES];
>>> but as I try to step over this, I end up back in setParentViewController with the parameter having changed to UINavigationController
>>> and the stack looking like this:
#0 0x00007f32 in -[ProjectEditorViewController setParentViewController:] at ProjectEditorViewController.m:32 #1 0x01708577 in -[UINavigationController pushViewController:transition:forceImmediate:]
#2      0x017031bb in -[UINavigationController pushViewController:animated:]
#3 0x00003d75 in -[ProjectsViewController addProject] at ProjectsViewController.m:76


So, why does setParentViewController get called twice, and why is the parameter type different the second time, and why don't I get an exception when the wrong type is gets passed into setParentViewController that second time?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to