How to pop from one view controller to another view controller

前端 未结 8 1323
北荒
北荒 2021-01-31 09:53

Using iOS I Have 15 ViewControllers now I want to pop from one ViewController to another View Controller.

I am using this code:

SecondViewController *Sec         


        
8条回答
  •  盖世英雄少女心
    2021-01-31 10:14

    First:

     SecondViewController *Sec=[SecondViewController alloc]init];
     [self.navigationController popViewController:Sec animated:YES];
    

    You can’t do this because you allocate a new Sec view controller that’s not in a navigation controller.

    Consider using this:

    You are in 9 view controller

    for (int i= 0 ; i < [[self.navigationController viewControllers]count] ; i++) {
        if ( [[[self.navigationController viewControllers] objectAtIndex:i] isKindOfClass:[FifiViewControllerClassname class]]) {
            [self.navigationController popToViewController:[array objectAtIndex:i] animated:YES];
        }
    }
    

提交回复
热议问题