当前位置: 代码迷 >> Iphone >> (iPhone/iPad开发)present某一个ViewController后,试图添加UINavigationController遇到的一些有关问题
  详细解决方案

(iPhone/iPad开发)present某一个ViewController后,试图添加UINavigationController遇到的一些有关问题

热度:33   发布时间:2016-04-25 06:07:25.0
(iPhone/iPad开发)present某一个ViewController后,试图添加UINavigationController遇到的一些问题

今天试图实现这么一个功能:通过presentViewController呈现某一个viewController,并且在这个页面中添加一个UINavigationController,可以达到在这个页面进行逐步跳转页面功能。


最初我是在跳转后的页面的initWithNibName等初始化函数添加UINavigationController,然后设置RootViewController为self,这样是实现了可以从当前界面跳转到其他界面,但是很快发现一个问题,当在界面中执行dismissViewController时,不会自动执行这个界面的dealloc()函数,也就意味着,内存中并没有释放之前present的那个界面,那个界面在添加UINavigationController时被retain了,可是几经尝试,在那个界面最终还是不容易自动执行dealloc()函数。


最后,我的解决方法是,在需要presentViewController处,添加UINavigationController,并设置rootViewController为需要present的view,present时将navigation那个对象传过去。具体实现代码如下:

KYPGRegistRootViewController *viewRegist = [[KYPGRegistRootViewController alloc] initWithNibName:@"KYPGRegistRootViewController" bundle:nil];    UINavigationController *navRegist = [[UINavigationController alloc] initWithRootViewController:viewRegist];    [viewRegist release];    if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {        [self.navigationController presentViewController:navRegist animated:YES completion:nil];    }else{        [self.navigationController presentModalViewController:navRegist animated:YES];    }    [navRegist release];


  相关解决方案