On Nov 16, 2012, at 8:28 PM, cocoa-dev-requ...@lists.apple.com wrote:

> Date: Fri, 16 Nov 2012 14:14:08 -0800
> From: Rick Mann <rm...@latencyzero.com>
> Subject: Bugs with parentViewController?
> 
> I'm finding that parentViewController is nil for all the 
> UINavigationControllers embedded in my hierarchy (via storyboard). In my 
> case, they're embedded in UISplitViewControllers.
> 
> I wrote bugs about this, but I wanted to check to see if others are seeing 
> that, or if I've failed to do something properly.

When you have questions of this sort, one useful approach, rather than asking 
others, is to test. When I say "test", I mean, isolate the issue entirely from 
the current project and work in a new project of utmost simplicity, so that 
whatever complications or mistakes the real project introduces are not 
introduced there. I am always surprised at the apparent failure of questioners 
to do this, as it is such a helpful and easy technique.

So, for example, in this case, one could do as follows:

Make a new project, for iPad only, using the Master-Detail template. That gives 
a UISplitViewController containing two UINavigationControllers, each containing 
a view controller as its root. Now put a button in the deepest detail 
controller in the storyboard, and connect its action to a method in 
DetailViewController.m that goes like this:

- (IBAction)doButton:(id)sender {
    UIViewController* vc = self;
    while (vc) {
        NSLog(@"%@", vc);
        vc = vc.parentViewController;
    }
}

Now run the project and tap the button. Here's the sort of thing that results:

2012-11-17 06:25:46.627 X[416:c07] <DetailViewController: 0x716c6a0>
2012-11-17 06:25:46.639 X[416:c07] <UINavigationController: 0x716c310>
2012-11-17 06:25:46.640 X[416:c07] <UISplitViewController: 0x7169090>

Now, it is a law of logic that one counterexample is sufficient to disprove an 
hypothesis. So if the hypothesis is that the parent is nil for navigation 
controllers in split view controllers in general, that idea is false. It is far 
more likely, therefore, that you've just hooked things together wrong, in your 
storyboard or in code, in your one particular case.

Another way to approach the matter is through logical thinking. The parent view 
controller chain is *crucial* to the entire workings of a modern iOS app. 
Therefore it seems most improbable that its integrity would be violated, as all 
sorts of things would break as a consequence. This reasoning has a somewhat 
Kantian a priori ring to it, but it is certainly suggestive that one would do 
better to doubt oneself rather than the framework in so vital and elementary a 
matter.

m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to