0

It's odd, I know, but even if you stated hidesBackButton to YES for the UINavigationItem associated with your view, you will be able to go back just touching the area that was meant to be a back button.

Sharing my solution... (more to come)

Aleks N.
  • 6,051
  • 3
  • 42
  • 42
  • Thanks for the tip, but please edit your question so that it contains only the question, and then post your answer as an answer. Otherwise, people searching will think the question remains unanswered. – hatfinch Aug 05 '09 at 11:10
  • Done. Although have to wait for 48 hours before marking the answer as an answer. :( – Aleks N. Aug 05 '09 at 12:20
  • As a note, this seems to be fixed in the latest version of XCode. – Dan F May 03 '12 at 17:37

2 Answers2

7

First I thought it was a simulator bug and uploaded to the device. But when I reproduced the same behavior there as well I started to think how to get rid of such behavior (since it was essential for me). Came up to such a solution:

[self.navigationItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithCustomView:[[UIView new] autorelease]] autorelease]];

And to show the back button again you write:

[self.navigationItem setLeftBarButtonItem:nil];

That's simple. Use it as a work-around, guys! Very strange this bug survived even in iPhone OS 3.0...

Aleks N.
  • 6,051
  • 3
  • 42
  • 42
  • Wouldn't it be easy to avoid all those autoreleases? I always alloc and release when unless I can't. – mk12 Aug 05 '09 at 14:22
  • True. But I was too lazy that time to create a couple of temp vars. :) – Aleks N. Aug 05 '09 at 18:32
  • I've used this in iOS 4 to get around a bug where the back button won't appear after using [self.navigationItem setHidesBackButton:BOOL] – Paul Ardeleanu Dec 20 '10 at 19:21
  • I can add that even under iOS7 this issue still appears in some cases :/ The solution still works though. =) – Widerberg Jul 02 '14 at 11:32
1

i think hiding back bar button also work as

self.navigationItem.hidesBackButton = TRUE;

Sandeep Kumar
  • 1,595
  • 1
  • 12
  • 19
  • Yes, it works. But it also does not prevent you from going back just by touching the place where the back button was meant to be. Please, re-read the post from the very beginning. – Aleks N. Aug 06 '09 at 07:19
  • UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title = @"Back"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release]; self.navigationItem.hidesBackButton = TRUE; Try this and give your title for that button . In my case it's working. (Not going back) – Sandeep Kumar Aug 06 '09 at 07:32
  • Ha-ha. Now see what _I_ am showing in the post. Whose approach is simpler? And what is TRUE doing in Objective C? Just hint. You're doing the same thing I do, but name it differently. Plus have an overhead with setting a value for hidesBackButton while I don't. Plus setting title for the button in your case doesn't have any sense since you will never see it. – Aleks N. Aug 06 '09 at 22:56
  • yes what u saying is absolutely right but that depends on requirement ? may be after some particular condition user come back to previous view? this is only restrict to user for a specific condition. in ur case if user can't see that button than how will be come back? – Sandeep Kumar Aug 08 '09 at 12:04
  • TRUE and YES are equivalent (basically a macro for the number 1) – kbanman Jan 25 '10 at 07:12