【发布时间】:2013-04-16 05:06:15
【问题描述】:
首先我像这样将我的 ViewController 添加到 NavigationController,
SecondViewController *viewControllerObj = [[SecondViewController alloc] init];
[self.navigationController pushViewController:viewControllerObj animated:YES];
[viewControllerObj release];`
但这会造成崩溃,当我在导航栏中按下返回按钮后将其推送到 SecondViewController。所以我在 .h 文件中创建 SecondViewController 对象作为属性并发布 像这样dealloc中的viewControllerObj,
现在我像这样将我的 ViewController 添加到 NavigationController,
在.h文件中,
@property (nonatomic,retain) SecondViewController *viewControllerObj;
在.m文件中,
self.viewControllerObj = [[SecondViewController alloc] init];
[self.navigationController pushViewController:self.viewControllerObj animated:YES];
[_viewControllerObj release]; // in dealloc method
当我分析我的项目时,这会在 viewControllerObj 上显示潜在泄漏,所以我已经像这样修改了我的代码,
SecondViewController *temp = [[SecondViewController alloc] init];
self.viewControllerObj = temp;
[temp release];
[self.navigationController pushViewController:self.viewControllerObj animated:YES];
现在我清除了潜在的泄漏
但我不知道这是否正确,是否每个viewController对象都需要声明为Property并在dealloc时释放????
【问题讨论】:
标签: ios uinavigationcontroller release