Reputation: 2551
In the transition between Storyboards generated NavigationBar. How do I assign onClick-function for BackNaviItem?
thanks
Navigationbar have generated automatically.
I write like this.
[[self.navigationItem backBarButtonItem] action:@selector(backNaviItemSenderEvent) forControlEvents:UiControlEvenTouchUpInside];
Does not work. (
Upvotes: 2
Views: 1896
Reputation: 8247
You can put any code that you need to perform on the back action in the viewWillDisappear
of your view controller that is being dismissed.
Alternatively you could set the navigationItem.leftBarButtonItem
with e.g. a Save button and link that to an outlet in your VC
. The back button is only shown if the leftBarButtonItem
is nil
.
Upvotes: 1
Reputation: 20541
Just Add this custom Button on UINavigationBar
, just override this button on BackButton and you can perform any action with click event just try it..
- (void)viewDidLoad
{
///write your code
UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
//[backbutton setImage:backButtonImage forState:UIControlStateNormal];//this line for set only image on button
[backbutton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
[backbutton setTitle:@"Back" forState:UIControlStateNormal];
backbutton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
UIBarButtonItem * back = [[UIBarButtonItem alloc] initWithCustomView:backbutton];
[backbutton addTarget:self action:@selector(yourButton_Clicked) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = back;
}
and when you click on this left button bellow method called...
-(void)yourButton_Clicked{
///Write your code here...
}
Upvotes: 0