工作开发在cell内播放视频的,在cell加载视频时网络较卡多次点击cell时,会出现重复触发push跳转多个控制器的情况。
多次点击TableViewCell重复触发push的最优解决方案
给出的解决方案:
-
给NavigationController一个标签push属性记录控制器的push转态。
-
在自定义的NIPNavigationController的方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
拦截是否正在push,如果是在push就直接return,否则跳转过来。 -
在代理方法
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
该方法执行标志着push成功,成功之后重置push标签NO。
少BB直接上代码:
@interface NIPNavigationController ()<UINavigationControllerDelegate>
// 记录push转态
@property (nonatomic, assign,getter=isPushing) BOOL pushing;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.isPushing == YES) {
return;
}else{
self.pushing = YES;
}
[super pushViewController:viewController animated:animated];
}
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
self.pushing = NO;
}
O(∩_∩)O~标题党,不过这种方案确实清爽呀!
网友评论