将 UINavigationController 添加到现有的 UIViewController

发布于 2024-10-16 23:09:51 字数 227 浏览 2 评论 0原文

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

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

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

How do I add an existing UIViewController (which is presented using presentModalViewController) to a UINavigationController?

When user tap on button, a new copy of my detail view need to be pushed. (In other words, pushViewController displaying pushViewController, modally, in a UINavigationController).

Easiest way to enable this functionality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷夜 2024-10-23 23:09:51

如何创建模态视图控制器?只需将控制器包装到 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];

how do you create your modal viewcontroller? Just wrap the controller into a UINavigationController

Let's assume your modal code is like this:

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

Then change it into something like this:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
终难愈 2024-10-23 23:09:51

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

在 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;
}

I think you need to add a navigation controller in your delegate, after that you can push the view. So that you can push the view from anywhere in your application.

on AppDelegate.h

UINavigationController *navig;

on 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文