方法一:在dealloc里面書寫監聽事件,因為只有pop才會調用dealloc,push不會掉用
- (void)dealloc {YLLog(@"123"); }
方法二:在- (void)viewWillDisappear:(BOOL)animated中調用
- (void)viewWillDisappear:(BOOL)animated{
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
NSLog(@"clicked navigationbar back button");
}
}
方法三:重寫返回按鈕,然后調用返回按鈕的方法即可:如
- (void)popViewcontrollerFunc {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"確定要放棄到手的獎品嗎" delegate:self cancelButtonTitle:@"點錯啦" otherButtonTitles:@"狠心放棄", nil];alert.tag = 10001;[alert show];
}