How to pop from one view controller to another view controller

前端 未结 8 1338
北荒
北荒 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:11

    BOOL check = FALSE;
    NSArray *viewControllers = [[self navigationController] viewControllers];
    id obj;
    for( int i=0;i<[viewControllers count];i++)
    {
        obj=[viewControllers objectAtIndex:i];
        if([obj isKindOfClass:[yourclassname class]])
        {
            check = TRUE;
            break;
        }
    }
    
    if (check)
    {
    
        [[self navigationController] popToViewController:obj animated:YES];
    }
    else
    {
        yourclassname *yourclassnameObj=[self.storyboard instantiateViewControllerWithIdentifier:@"yourclassStoryBoardID"];
        [self.navigationController pushViewController:yourclassnameObj animated:true];
    
    }
    

提交回复
热议问题