I customized back button. and then I wanted the backButtonTapped
be called when tapping on back button. but it is not called.
UIImage *backBtn = [UIImage imageNamed:@"back-image"];
backBtn = [backBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.navigationBar.backIndicatorImage = backBtn;
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = backBtn;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.navigationItem.backBarButtonItem.style target:self action:@selector(backButtonTapped)];
- (void) backButtonTapped {
[self.navigationController popViewControllerAnimated:YES];
}
try below code - work for me and if you have issue then put comment, i will help you
UIImage *image1 = [UIImage imageNamed:@"back-image"];
CGRect frame = CGRectMake(0, 0, image1.size.width, image1.size.height);
UIButton* backbtn = [[UIButton alloc] initWithFrame:frame];
[backbtn setBackgroundImage:image1 forState:UIControlStateNormal];
[backbtn addTarget:self action:@selector(backButtonTapped) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbtn];
[self.navigationItem setLeftBarButtonItem:backButtonItem];
-(void)backButtonTapped {
[self.navigationController popViewControllerAnimated:YES]; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.