我有一个UITableViewController。当你选择一个单元格时,它会在UIViewController上调用init,它以编程方式创建一堆视图并将它们添加到屏幕上。这里的一切都很好。
当用户与应用程序交互时,会移动或删除视图。我希望有一个按钮,用户可以“重新开始”,UIViewController将在屏幕上初始化并绘制新内容。基本上我想要的行为就像用户“回”到UITableViewController并再次点击同一项一样。
我可以创建按钮并将其连接起来。我需要知道的是如何释放和重新初始化UIViewController。
我该怎么做?
答案 0 :(得分:2)
在UIMyViewController
控制器中创建 UIViews 。
并使用以下代码在导航堆栈中推送视图控制器。
-(void) buttonClcked:(id) sender
{
//Create for pushing another view controller in navigation stack.
UIMyViewController *myViewController = [[UIMyViewController alloc] init];
//to push view controller in navigation stack.
[self.navigationController pushViewController:myViewController animated:YES];
// you could release it because now it's retained by your UINavigationController
[myViewController release];
myViewController = nil;
}
答案 1 :(得分:0)
嗯,在我看来,你有两个选择: