2017-04-11 94 views
0

最近,一個奇怪的問題發生時,我把ViewController推到下一個viewController。 爲什麼我認爲這是一個奇怪的問題?因爲它並不總是出現(發生的可能性很低)。當它出現時,下一個viewController只在屏幕上顯示其導航欄,我仍然可以看到rootViewController,但沒有反應就觸摸它(PopGesture是有效的)。希望能得到你的幫助,非常感謝。發生故障當我pushViewController

enter image description here

#pragram mark - method of pushing 
- (void)clickToAccout { 

    if (![self countTotalSelectedNumber]) { 
     [SVProgressHUD showInfoWithStatus:@"沒有被選擇的商品"]; 
     return; 
    } 

    CSCreatOrderViewController *creatOrderVC = [[CSCreatOrderViewController alloc] init]; 
    creatOrderVC.totalPrice = [self countTotalPrice]; 
    creatOrderVC.goods = [self selectedGoods]; 

    [self.navigationController pushViewController:creatOrderVC animated:YES]; 
} 

#pragma mark - chlid class of navgationController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.navigationBar.tintColor = [UIColor whiteColor]; 
} 

- (UIStatusBarStyle)preferredStatusBarStyle { 
    return _barStyle; 
} 

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
    if (self.viewControllers.count > 0) { 
     viewController.hidesBottomBarWhenPushed = YES; 
     [SVProgressHUD dismiss]; 
    } 

    [super pushViewController:viewController animated:animated]; 
} 

- (UIViewController *)popViewControllerAnimated:(BOOL)animated { 
    [SVProgressHUD dismiss]; 

    return [super popViewControllerAnimated:animated]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


#pragma mark - tabBarController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    CSTabBar *tabBar = [[CSTabBar alloc] init]; 
    [self setValue:tabBar forKey:@"tabBar"]; 

    [self.tabBar setTintColor:[UIColor cz_colorWithHex:0Xec5151]]; 

    [self addChildViewControllerWithTitle:@"首頁" imageName:@"home" controllerName:@"CSHomeViewController"]; 
    [self addChildViewControllerWithTitle:@"分類" imageName:@"classify" controllerName:@"CSClassifyViewController"]; 
    [self addChildViewControllerWithTitle:@"查詢" imageName:@"search" controllerName:@"CSSearchViewController"]; 
    [self addChildViewControllerWithTitle:@"購物車" imageName:@"cart" controllerName:@"CSShoppingCartViewController"]; 
    [self addChildViewControllerWithTitle:@"我的" imageName:@"mine" controllerName:@"CSMineViewController"]; 

    self.selectedIndex = 0; 
} 

- (void)addChildViewControllerWithTitle:(NSString *)title imageName:(NSString *)imageName controllerName:(NSString *)controllerName { 

    Class cls = NSClassFromString(controllerName); 

    UIViewController *vc = [[cls alloc] init]; 
    vc.title = title; 
    [vc.tabBarItem setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]]; 
    [vc.tabBarItem setSelectedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]]]; 
    vc.tabBarItem.title = title; 

    CSNavigationController *nav = [[CSNavigationController alloc] initWithRootViewController:vc]; 
    [self addChildViewController:nav]; 
} 


#pragma mark - base viewController 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.view.backgroundColor = [UIColor whiteColor]; 

    [self setupNavItem]; 

    self.navigationController.interactivePopGestureRecognizer.enabled = YES; 
    self.navigationController.interactivePopGestureRecognizer.delegate = self; 

    _indciatorView = [[CSIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    UIWindow *keyW = [UIApplication sharedApplication].keyWindow; 
    [keyW addSubview:_indciatorView]; 

    [_indciatorView mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.center.equalTo(keyW); 
    }]; 
} 


- (void)setupNavItem { 

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; 
    button.imageEdgeInsets = UIEdgeInsetsMake(9, 0, 9, 29); 
    [button setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(clickToDismiss) forControlEvents:UIControlEventTouchUpInside]; 

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 
} 

- (void)clickToDismiss { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 
+0

你能在一些代碼中編輯你的文章嗎? –

+0

好吧,等待幾分鐘 – wakakaJP

+0

因爲這個問題可能發生在我所有的根視圖控制器上,所以我懷疑基本視圖控制器有問題,但我找不到它 – wakakaJP

回答

0

我想你應該改變

[super pushViewController:viewController animated:animated]; 

[self.navigationController pushViewController:viewController animated:animated]; 

而同樣的,當彈出

[super popViewControllerAnimated:animated]; 

[self.navigationController popViewControllerAnimated:animated]; 
+0

你懷疑代碼是我的UINavgationController的包裝子類,所以我認爲你所說的無法解決我的問題,但我會朝這個方向努力,謝謝你的幫助。 – wakakaJP

0

我清楚的Xcode的高速緩存,這種情況不會出現。也許我導入了第三個lib之前導致了這種情況。但是就像我問的那樣,它並不總是出現(發生的概率很低)。所以,希望它一直很好。

+0

這個問題再次發生,我會從手勢識別器 – wakakaJP