How can I remove a view from navigation controller

前端 未结 5 2068
不思量自难忘°
不思量自难忘° 2020-12-14 11:36

I want to call a new view controller and remove the current view controller from the navigation controller stack. For example. I am in view controller A and I call B.

<
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 12:33

    This is the answer.

    The following code pops the current view controller.

    UINavigationController *navController = self.navigationController;
    // retain ourselves so that the controller will still exist once it's popped off
    [[self retain] autorelease];
    [navController popViewControllerAnimated:NO];
    

    And this pushes the new one:

    ViewControllerC *viewC = [[ViewControllerC alloc] init];
    [navController pushViewController:viewC animated:TRUE];
    

    Hope it helps!

提交回复
热议问题