【问题标题】:Adding UINavigationController to existing UIViewController将 UINavigationController 添加到现有的 UIViewController
【发布时间】:2011-06-24 21:06:26
【问题描述】:

如何将现有的 UIViewController(使用 presentModalViewController 呈现)添加到 UINavigationController?

当用户点击按钮时,需要推送我的详细视图的新副本。 (换句话说,pushViewController 在 UINavigationController 中模态地显示 pushViewController)。

启用此功能的最简单方法是什么?

【问题讨论】:

  • 不清楚你在问什么。您想以模态方式呈现 UINavigationController 吗?那“感觉”不对,但我不确定。
  • 这是简化的描述...以模态方式呈现 UINavigationController...(但修改现有的 UIViewController)

标签: iphone xcode uiviewcontroller uinavigationcontroller


【解决方案1】:

我认为您需要在您的委托中添加一个导航控制器,然后您可以推送视图。这样您就可以从应用程序的任何位置推送视图。

在 AppDelegate.h 上

UINavigationController *navig;

在 AppDelegate.M 上

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    navig = [[UINavigationController alloc] initwithRootViewController:viewController.view];

    //[navig pushViewController:viewController animated:YES];
    [self.window addSubview:navig.view];
    [self.window makeKeyAndVisible];

    return YES;
}

【讨论】:

  • 我无法理解这个问题或看到这个答案的相关性:)。
  • 你要推送newdetailview控制器,所以你应该有导航控制器然后你可以推送
  • 如果您将在应用程序委托中添加导航控制器,则仅从类中的任何位置推送视图。因为如果您的应用程序是基于视图的应用程序,那么导航控制器不起作用,所以最好在委托中添加导航控制器,您可以轻松推送视图。看我的回答,我已经编辑了。
【解决方案2】:

如何创建模态视图控制器?只需将控制器包装成 UINavigationController

假设你的模态代码是这样的:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
[self presentModalViewController:vc animated:YES];

然后改成这样:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];

【讨论】:

  • navController的viewControllers属性中有MyExampleViewController和MyDetailViewController。但是屏幕没有更新(MyDetailViewController 没有显示)?
  • MyExampleViewController中如何调用pushViewController?
  • [self.navigationController pushViewController:anotherVC animated:YES];?!
  • 我用这个方法来。但是我不能在我的生活中添加一个 UIBarButtonItem 到导航控制器附带的工具栏。任何帮助将不胜感激?
  • self.navigationItem.rightBarButtonItem = yourUIBarButtonItem; 不起作用?顺便说一句,它不是工具栏,而是导航栏。也许您应该为您的问题创建一个新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-10
  • 2014-04-03
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 2011-05-13
相关资源
最近更新 更多