关于视图切换

今天在写代码中突然遇到一个问题,自以为在一个UIPickPhotoViewController切换到VideoPageViewController中,UIPickPhotoViewController和VideoPageViewController都是MainViewController  pushViewController方法推出来的,因此在UIPickPhotoViewController中写的代码如下:

VideoPageViewController *VideoController = [[VideoPageViewController alloc] init];
            [self.navigationController popViewControllerAnimated:NO];
            [self.navigationController pushViewController:VideoController animated:YES];
            [VideoController release]; 

结果这样根本就push不出来VideoController,后来才发现,原来是因为当你执行[self.navigationController popViewControllerAnimated:NO];这句代码的时候,你就把自己给pop掉了,所以self.navigationController 应该为nil了,再来执行 [self.navigationController pushViewController:VideoController animated:YES];应该是没效果了。所以想要然[self.navigationController pushViewController:VideoController animated:YES];这句代码有效,只要把self.navigationController 临时的保存起来就OK了。把上面的代码改成:

 VideoPageViewController *VideoController = [[VideoPageViewController alloc] init];
            UINavigationController *tmpNavController = self.navigationController;
            [tmpNavController popViewControllerAnimated:NO];
            [tmpNavController pushViewController:VideoController animated:YES];
            [VideoController release];  

这样VideoController就能够被push出来了。

 

 
原文地址:https://www.cnblogs.com/lyanet/p/2785254.html