简体   繁体   English

使用UINavigationController生成同一视图的新实例

[英]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.

相关问题 iPhone:UINavigationController不显示新视图 - iPhone: UINavigationController not showing new view 如何将一个新的视图实例推到同一视图之上? - How can I push a new instance of a view on top of the same view? UINavigationController popToRootViewController,然后立即推送一个新视图 - UINavigationController popToRootViewController, and then immediately push a new view 在UINavigationController中为所有视图控制器添加相同的按钮 - Adding same button to all view controllers in UINavigationController UINavigationController,在堆栈上具有相同视图控制器的两个副本 - UINavigationController with two copies of the same view controller on stack 是否建议在UINavigationController视图和模态视图中使用相同的xib? - Is it advisable to use the same xib in a UINavigationController view and a modal view? 使用UINavigationController时,表视图下移 - Table view shifts down when using a UINavigationController 在UINavigationController中推送相同类的视图控制器的不同对象 - Push different objects of view controller of same class in UINavigationController 使用uinavigationcontroller的基于视图的应用中的ipad旋转问题 - ipad rotation problem in a view based app using uinavigationcontroller 如何在使用UINavigationController时调整视图大小setToolbarHidden:animated: - How to resize view when using UINavigationController setToolbarHidden:animated:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM