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.
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