美文网首页iOS开发精华专题iOS开发技术分享iOS学习开发
iOS开发判断当前ViewController是push还是pr

iOS开发判断当前ViewController是push还是pr

作者: Courage_SC | 来源:发表于2016-05-23 16:46 被阅读1821次

通过presentviewcontroller的方式显示的viewcontroller不会存入self.navigationController.viewControllers数组中。而通过push方式显示的viewcontroller会存在该数组的最后。

NSArray *viewcontrollers=self.navigationController.viewControllers;
    if (viewcontrollers.count>1) {
        if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {
            //push方式
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    else{
        //present方式
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }

相关文章

网友评论

  • 00after: if (self.navigationController.viewControllers.count > 1 && [self.navigationController.viewControllers lastObject] == self) {
    [self.navigationController popViewControllerAnimated:animated];
    } else {
    [self dismissViewControllerAnimated:animated completion:nil];
    }
  • 4dfb3c62dd01:可以用navigationcontroller 的topViewController判断
  • geekAppke:判断当前显示控制器的presentingViewController属性,存在就是modal出来的,为nil就是push进来的
    Courage_SC:@M爱学习 :+1::+1:

本文标题:iOS开发判断当前ViewController是push还是pr

本文链接:https://www.haomeiwen.com/subject/fwuarttx.html