每次我将视图控制器压入堆栈时,如何从 appDelegate 重新加载视图控制器?
目前,我的应用程序有一个导航屏幕,允许用户选择其他视图。单击时,navController 只需推送相关的特定视图控制器。如果我再也没有回到相同的视图并期望它被重新加载,那么这非常有用。
在下面的代码中,我根据请求推送视图控制器。
- (void)optionClicked:(NSString *)optionName
{
if ([@"First" isEqualToString:optionName]) {
[navController pushViewController:firstController animated:YES];
} else if ([@"Next" isEqualToString:optionName]) {
[navController pushViewController:nextController animated:YES];
}
}
完成视图后,我只需将其从堆栈中弹出即可。但是,下次用户从菜单中选择相同的选项时,它不会“干净”加载,这就是我的问题所在。每次将视图控制器推入堆栈时,如何加载新的视图控制器?
Currently my application has a single navigation screen that allows the user to select other views. When clicked the navController simply does a push of the specific view controller in question. This works great if I never come back to the same view again expecting it to be reloaded.
In the code below I push a view controller when requested.
- (void)optionClicked:(NSString *)optionName
{
if ([@"First" isEqualToString:optionName]) {
[navController pushViewController:firstController animated:YES];
} else if ([@"Next" isEqualToString:optionName]) {
[navController pushViewController:nextController animated:YES];
}
}
When done with a view I simply pop it from the stack. But the next time a user selects this same option from the menu it's not loaded "clean" and this is where my question comes in. How can I load a view controller fresh each time it's pushed on the stack?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须重新初始化视图控制器。
在这种情况下,我建议使用带有保留的属性。
@property (nonatomic, keep) MyViewControllerSubclass *firstController;
这样你就可以使用
self.firstController = [[[MyViewControllerSubclass alloc] init] autorelease]; 内存管理是大部分是为你做的。 (尽管你仍然需要在 dealloc 中释放。)
You have to reinitialize the viewcontroller.
In this situation I would suggest using a property with retain on it.
@property (nonatomic, retain) MyViewControllerSubclass *firstController;
that way you can use
self.firstController = [[[MyViewControllerSubclass alloc] init] autorelease];
and the memory management is mostly done for you. (Although you still have to release in dealloc.)