I have a UIBarButtonItem and would like to programmatically set the action that goes to the previous controller (in my case, my previous view is a UITableViewController).
Below is my code that I am currently using to make the bar button item although the button doesn't go to the previous view yet.
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:nil action:nil];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Website"];
item.leftBarButtonItem = leftButton;
item.hidesBackButton = YES;
[myBar pushNavigationItem:item animated:NO];
You could write this in your
viewDidLoad
method:and then use this:
[self dismissViewControllerAnimated:YES completion:nil];
Add following code in your controller, in
- (void)viewDidLoad
function:call
[self addBackButtonWithTitle:@"back"];
if You want to custom backbutton with title.or
[self addBackButtonWithImageName:@"back_button_image_name"];
if You want custom backbutton with image.