views:

49

answers:

1

Hey guys...

I'm stuck trying to pop a TTPhotoViewController from three20. At first it did not come with a back button, but I have now implemented it and tried to pop the view with no luck. Here's a snippet of my code:

Button (this works) --

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:TTLocalizedString(@"Back", @"Back to Albums") style:UIBarButtonItemStyleBordered target:self action:@selector(popView)];

-popView (method is called, but statement does NOT work) --

- (void) popView {
    [self.navigationController popViewControllerAnimated:NO]; 
}

thanks

UPDATE 0 -

This is the code that ttphotoviewcontroller had in its init (I checked that the program was running this) --

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
      self.navigationItem.backBarButtonItem =
      [[[UIBarButtonItem alloc]
      initWithTitle:
      TTLocalizedString(@"Photo",
         @"Title for back button that returns to photo browser")
      style: UIBarButtonItemStylePlain
      target: nil
      action: nil] autorelease];

      self.statusBarStyle = UIStatusBarStyleBlackTranslucent;
      self.navigationBarStyle = UIBarStyleBlackTranslucent;
      self.navigationBarTintColor = nil;
      self.wantsFullScreenLayout = YES;
      self.hidesBottomBarWhenPushed = YES;

      self.defaultImage = TTIMAGE(@"bundle://Three20.bundle/images/photoDefault.png");
  }

return self;
}

It was already adding a back button, but alas this code also doesn't add a button to my navbar.

+1  A: 

If you are doing something similar to what he did in the Catalog example, then you just add this in the root view controller (i.e. NOT in the view that will appear after it gets pushed onto the stack, but in the parent view).

This action is no different from regular iPhone UINavigationController actions.

- (id)init {
    if (self = [super init]) {

    // setup back button for nav controller
    self.navigationItem.backBarButtonItem =
      [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered
      target:nil action:nil] autorelease];

    }
}

When the new view gets pushed onto the stack, it will use that back button to return. You shouldn't have to call popView or anything else. Notice I am using backBarButtonItem whereas you are using leftBarButtonItem (which you only use if you are using a custom back button).

For more information, read the "Updating the Navigation Bar" section of this document

iWasRobbed
thanks for your reply. I tried it and it looks like it didn't work.. I've updated my question to include more details.
jmont
Are you inheriting from TTNavigator or from your own navigation? You are right in that it doesn't add the back button there (I just tried commenting out all that code and it still gets the back button from somewhere). However, when I searched for `BarButtonItem` within the code, I'm not finding anywhere else. I'm not sure how he's adding those in.
iWasRobbed
In my project, I am using `MockPhotoSource` and `PhotoTest1Controller` from the `Catalog` example, and it automagically creates the back button for me (and pops the view as well). He might just be letting it inherit from Apple's navigation class since I can change the back button text with my code above.
iWasRobbed
I tried your code in my project and it works fine in my `viewDidLoad` method for my photo view controller. I put an NSLog in the `popView` method to make sure it got called and it did
iWasRobbed
thanks, mine gets called too, it just doesn't pop the view controller.... I'm gonna try the catalog example and let you know.
jmont
AHH!! back button does NOT work on TTCatalog on simulator.....
jmont
TTCatalog back button doesn't work straight out of the box? I would verify you can get navigation working in another app (like Apple's UICatalog http://developer.apple.com/iphone/library/samplecode/UICatalog/Introduction/Intro.html) and work from there. Sounds like you may have something else going on.
iWasRobbed