Reputation: 17651
I need to have a UIButton (with a class of RtnBtn) which basically replicates the back button action used in the navigation bar action at the end of a process - I'm fairly new to IOS dev and I'm not sure how to approach this - should it be done via a push or is there a better option to apply coded action directly to the button?
Upvotes: 1
Views: 930
Reputation: 484
Can you post some code here, what you have done?, you can add custom back button by below code,
UIButton *buttonBack = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonBack setBackgroundImage:YOURImage forState:UIControlStateNormal];
[buttonBack addTarget:self action:@selector(backPressed) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithCustomView:buttonBack] autorelease];
self.navigationItem.leftBarButtonItem = backButton;
Method to handle event,
-(void)backPressed
{
[self.navigationController popViewControllerAnimated:YES];
}
Upvotes: 1
Reputation: 1069
If I did not understand wrong, you need this;
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 1
Reputation: 11970
You need to create the button, specify a selector as it's action, and in that method call popViewController:animated:
on your navigation controller.
Upvotes: 1