• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[iPhone] weird crash (aren't they all?): ivar seems to be dynamically changing its type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iPhone] weird crash (aren't they all?): ivar seems to be dynamically changing its type


  • Subject: [iPhone] weird crash (aren't they all?): ivar seems to be dynamically changing its type
  • From: Paul Archibald <email@hidden>
  • Date: Fri, 20 Nov 2009 15:55:14 -0800

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: [iPhone] weird crash (aren't they all?): ivar seems to be dynamically changing its type
      • From: Michael Babin <email@hidden>
  • Prev by Date: Re: tableView:setObjectValue:forTableColumn:row: not called when button pressed
  • Next by Date: Re: [iPhone] weird crash (aren't they all?): ivar seems to be dynamically changing its type
  • Previous by thread: Re: Magic Mouse and NSTouch
  • Next by thread: Re: [iPhone] weird crash (aren't they all?): ivar seems to be dynamically changing its type
  • Index(es):
    • Date
    • Thread