首页 > 移动平台 > 详细

iOS开发~防止navigation多次push一个页面

时间:2019-10-22 15:33:10      阅读:148      评论:0      收藏:0      [点我收藏+]

在点击push下一个页面时,因为各种原因,点一下cell或按钮没有响应,用户可能就多点几下,这时候会打开好几个一样的页面。

这是因为push后的页面有耗时操作或者刚好push到另一个页面时,另一个页面正好在reloadData卡住主线程。造成点击cell时卡住了。

这时,我们可以通过重写导航控制器的方法来解决这个问题。


#import <UIKit/UIKit.h>

@interface NaviViewController : UINavigationController

@end


#import "NaviViewController.h"

@interface NaviViewController ()<UINavigationControllerDelegate>
// 记录push标志
@property (nonatomic, getter=isPushing) BOOL pushing;
@end

@implementation NaviViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.delegate = self;
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.pushing == YES) {
NSLog(@"被拦截");
return;
} else {
NSLog(@"push");
self.pushing = YES;
}

[super pushViewController:viewController animated:animated];
}


#pragma mark - UINavigationControllerDelegate
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
self.pushing = NO;
}
@end

 

iOS开发~防止navigation多次push一个页面

原文:https://www.cnblogs.com/huangzs/p/11719929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!