拦截iOS系统导航栏返回按钮事件-三种方法

方法一:在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];

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容