pop回指定控制器

//OC
NSArray *array = [NSMutableArray new]; array = self.navigationController.viewControllers; //1、返回指定index的控制器 UIViewController *viewC = [array objectAtIndex:0]; [self.navigationController popToViewController:viewC animated:YES]; //2、 UIViewController *viewc = [UIViewController new]; for (viewc in array) { if ([viewc isKindOfClass:[指定控制器 class]]) { [self.navigationController popToViewController:viewcanimated:YES]; } }

//3、

 [vcArr removeObject:strongSelf];

  [self.navigationController setViewControllers:vcArr animated:NO];

 

 2、Swift

//返回指定界面
let marr = NSMutableArray.init(array:(self.navigationController?.viewControllers)!)
for i in 0..<marr.count {
     let vc = marr[i] as! UIViewController
     let vcName = type(of: vc)
     let PurposeVCName = type(of: 指定控制器名称())
     if "\(PurposeVCName)" == "\(vcName)" {
          self.navigationController?.popToViewController(vc, animated: true)
     }
}
let marr = NSMutableArray.init(array:(self.navigationController?.viewControllers)!)
for i in 0..<marr.count {
    let vc = marr[i] as! UIViewController
    let vcName = type(of: vc)
    let PurposeName = type(of: 指定控制器的后一个控制器名称())
    if "\(PurposeName)" == "\(vcName)" {
       let popVC = self.navigationController?.viewControllers[i-1]
       self.navigationController?.popToViewController(popVC!, animated: true)
    }
}
//将本控制器从导航栏控制器数组中移除,从而返回到跳转到本控制器的控制器
let marr = NSMutableArray.init(array(self.navigationController?.viewControllers)!) let removeArr = NSMutableArray() for i in 0..<marr.count { let vc = marr[i] as! UIViewController let vcName = type(of: vc) let selfName = type(of: self) if "\(selfName)" == "\(vcName)" { removeArr.add(vc) } } if removeArr.count > 0 { for i in 0..<removeArr.count { let vc = removeArr[i] as! UIViewController marr.remove(vc) } } let array : NSArray = marr self.navigationController?.viewControllers = array as! [UIViewController]

 

posted on 2017-04-26 14:51  MJ_Angel  阅读(322)  评论(0编辑  收藏  举报

导航