1. 程式人生 > >[IOS]防止多次push一個頁面

[IOS]防止多次push一個頁面

一個按鈕push到另外一個頁面 ,有時會出現push兩次重複頁面的效果 。

解決方式如下:

這裡遵守協議 定義一個push的bool值來判斷是否正在push。

@interfaceStartViewController ()<UIScrollViewDelegate,UINavigationControllerDelegate>

@property (nonatomic,getter=isPushing)BOOL pushing;

- (void)pushViewController:(UIViewController *)viewController animated:(

BOOL)animated {

if (self.pushing ==YES) {

NSLog(@"被攔截");

return;

    }else {

NSLog(@"push");

self.pushing =YES;

    }

    [self.navigationControllerpushViewController:viewControlleranimated:animated];

}

#pragma mark - UINavigationControllerDelegate

-(void)navigationController:(UINavigationController

*)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

self.pushing =NO;

}