1

I am trying to add a function to navigation back button, but it is not working. following is my code:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(removePinsOfMap:)];
    self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}


- (void) removePinsOfMap: (UIBarButtonItem *)sender{
    NSLog(@"HI");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   // Dispose of any resources that can be recreated.
}

-(void) viewWillDisappear:(BOOL)animated {
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        // back button was pressed.  We know this is true because self is no longer
        // in the navigation stack.
    }
    [super viewWillDisappear:animated];
}

I don't know why it won't log "hi" to my console

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
Kai Li
  • 11
  • 3

0 Answers0