Re: [iPhone 3.1] navigationItem.backBarButtonItem weirdness
Re: [iPhone 3.1] navigationItem.backBarButtonItem weirdness
- Subject: Re: [iPhone 3.1] navigationItem.backBarButtonItem weirdness
- From: Roland King <email@hidden>
- Date: Thu, 11 Feb 2010 12:36:38 +0800
well here's what the documentation has to say about the backBarButtonItem property you are trying to set.
When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title.
Did you read it, you should always have a peek at the documentation when something does something you didn't expect.
"The target and action of the back bar button item you set should be nil"
From that I assume that, on setting the back bar button item, the navigation controller sets a method on itself as the recipient of the action and whatever you set, it throws away. That makes sense, the back button item should go back, that's the expected behaviour and if anyone wants to do something custom, you have delegate methods for that which the nav controller calls for you.
Might be nice if the framework asserted on stuff like this, actually there are quite a lot of cases in which it does, this doesn't seem to be one of them.
On 11-Feb-2010, at 8:10 AM, John Michael Zorko wrote:
>
> Hello, all ...
>
> I've a question about the UINavigationController backBarButtonItem property. I wanted to merely set my own image for the back button, instead of it using the title of the controller above in the hierarchy. So, this is what I did (yes this app is using Three20, but I don't think that's the reason):
>
> - (id)initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query
> {
> if (self = [super initWithNavigatorURL:URL query:query])
> {
> self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backarrow.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back)] autorelease];
> }
>
> return self;
> }
>
> - (void)back:(id)sender
> {
> }
>
> Now, this worked -- but I wasn't _expecting_ it to work. I was expecting that my "back" selector would be called, and I would have to tell the nav controller to pop. However, my "back" selector isn't called, and the back button _works_ like it always has. While i'm not in any way against freebees like this, i'm a bit concerned as to _why_ it works like this. Any explanation would be appreciated, explanations that actually edify me more so :-)
>
> Regards,
>
> John
>
>
> _______________________________________________
>
> 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
_______________________________________________
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