[英]Spawning a new instance of the same view, using a UINavigationController
I'm currently trying to spawn a new instance of the same view - using the following code: 我目前正在尝试使用以下代码生成同一视图的新实例:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
InventoryController *inventoryController = [[InventoryController alloc] initWithNibName:@"InventoryView" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self];
[navigationController pushViewController:inventoryController animated:YES];
[inventoryController release];
[navigationController release];
}
Problem is that it's not working... 问题是它不起作用...
I don't get any errors or anything - it just doesn't do anything. 我没有任何错误或任何东西-它什么也没做。
Any ideas? 有任何想法吗?
@PengOne has it right... you're creating a navigation controller and then releasing it, and there's nothing to prevent it from being deallocated. @PengOne正确...您正在创建一个导航控制器,然后释放它,没有阻止它释放的措施。 Additionally, you haven't added the nav controller's view to the window, and you haven't set the nav controller as the window's root view controller, so there's no way for the views controlled by controllers in this particular navigation stack to ever be seen.
此外,您尚未将导航控制器的视图添加到窗口中,也没有将导航控制器设置为窗口的根视图控制器,因此无法看到此特定导航堆栈中由控制器控制的视图。
Try this: Create a navigation-based project in Xcode. 尝试以下操作:在Xcode中创建一个基于导航的项目。 You don't need to add any code -- just create the project so that you can look at the code that's provided.
您无需添加任何代码-只需创建项目即可查看提供的代码。 You'll see that the app delegate has a retain property for storing the nav controller, and the nav controller is set as the window's root view controller.
您将看到应用程序委托具有保留属性,用于存储nav控制器,并且nav控制器被设置为窗口的根视图控制器。
If your current controller is already a part of UINavigationController hierarchy then you must not create a new navigation controller - use the existing one instead (note that every UIViewController has a reference to its parent UINavigationViewController if it exists): 如果您当前的控制器已经是UINavigationController层次结构的一部分,则您不能创建一个新的导航控制器-改用现有的导航控制器(请注意,每个UIViewController都有对其父UINavigationViewController的引用(如果存在):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
InventoryController *inventoryController = [[InventoryController alloc] initWithNibName:@"InventoryView" bundle:nil];
[self.navigationController pushViewController:inventoryController animated:YES];
[inventoryController release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.