iPhone将视图控制器推入导航栏内的标签栏内

发布于 2024-11-30 21:22:28 字数 1671 浏览 0 评论 0原文

我有一个应用程序,它有一个带导航栏的选项卡栏,

选项卡栏正在显示, 并工作,但是当我想转到其中一个选项卡内的另一个页面时,它不会加载新页面,

这里我的应用程序委托

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    



self.tabBarController = [[[UITabBarController alloc] init] autorelease];


StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo recomendado por apple!!!
PhotosViewController* PhotosViewController_ = [[[PhotosViewController alloc] init] autorelease];
VideosViewController* VideosViewController_ = [[[VideosViewController alloc] init] autorelease];
SocialViewController* SocialViewController_ = [[[SocialViewController alloc] init] autorelease];



NSArray* controllers = [NSArray arrayWithObjects: startViewControllerView, VideosViewController_, PhotosViewController_, SocialViewController_, nil];

    self.tabBarController.viewControllers = controllers;
self.pagesNavigation = [[[UINavigationController alloc] initWithRootViewController:startViewControllerView] autorelease];
self.pagesNavigation.navigationBarHidden = NO;

[self tabBarConfig];

[self.tabBarController setViewControllers:controllers animated:YES];


[self.window addSubview:self.pagesNavigation.view];





self.window.rootViewController = self.tabBarController;

//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    [self.window makeKeyAndVisible];

return YES;



}

它显示选项卡正常,

但在其中一个页面中我推送了新视图,

[self.navigationController pushViewController:bigPhotoView animated:YES];

但它没有加载不工作。

那么如何从我的选项卡加载新视图呢?

I have an app that has a tabBar with a navbar,

The tabBar is showing,
and working, but when I want to go to another page inside one of the tabs, it doesnt load the new page,

here my app delegate

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    



self.tabBarController = [[[UITabBarController alloc] init] autorelease];


StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo recomendado por apple!!!
PhotosViewController* PhotosViewController_ = [[[PhotosViewController alloc] init] autorelease];
VideosViewController* VideosViewController_ = [[[VideosViewController alloc] init] autorelease];
SocialViewController* SocialViewController_ = [[[SocialViewController alloc] init] autorelease];



NSArray* controllers = [NSArray arrayWithObjects: startViewControllerView, VideosViewController_, PhotosViewController_, SocialViewController_, nil];

    self.tabBarController.viewControllers = controllers;
self.pagesNavigation = [[[UINavigationController alloc] initWithRootViewController:startViewControllerView] autorelease];
self.pagesNavigation.navigationBarHidden = NO;

[self tabBarConfig];

[self.tabBarController setViewControllers:controllers animated:YES];


[self.window addSubview:self.pagesNavigation.view];





self.window.rootViewController = self.tabBarController;

//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    [self.window makeKeyAndVisible];

return YES;



}

it shows tabs ok,

but in one of the pages I push the new view with

[self.navigationController pushViewController:bigPhotoView animated:YES];

but it doesn't work.

So how to load the new view from my tab?

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

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

发布评论

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

评论(1

℡寂寞咖啡 2024-12-07 21:22:28

UINavigationController 是一堆视图控制器。每个视图控制器都有一个名为 navigationController 的属性,它代表它所属的 UINavigationController。因此,如果视图控制器不属于 UINavigationController (换句话说,如果视图控制器不存在于堆栈中),它的 navigationController 属性将为 nil 。

如果你想要一个视图控制器,你可以从中推送新的视图控制器和弹出视图控制器,你需要首先创建一个堆栈(UINavigationController),将你的视图控制器推送到这个堆栈中。现在,由于堆栈存在,我们可以继续在该堆栈中推送新的视图控制器。

您的 bigPhotoView 没有被推送,可能是因为当前视图控制器不存在 UINavigationController (您试图从中推送 bigPhotoView)。这可以如下验证:

if (self.navigationController != nil) {
    [self.navigationController pushViewController:bigPhotoView animated:YES];
}

在上述情况下,您可能不会输入 if 语句。

我简单地准备了你的功能。它看起来像这样。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Create Start view controller.
    StartViewController *startController = [[StartViewController alloc] init];
    UINavigationController *startViewNavigationController = [[UINavigationController alloc] initWithRootViewController:startController];
    [startController release];

    // Similarly create for photos, videos and social...

    // Create an array of view controllers.
    NSArray* controllers = [NSArray arrayWithObjects:startViewNavigationController, photosViewNavigationController, videosViewNavigationController, socialViewNavigationController, nil];

    // Create our tab bar controller.
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];

    // Set the view controllers of the tab bar controller.
    self.tabBarController.viewControllers = controllers;

    // Release the startViewNavigationController, photosViewNavigationController, videosViewNavigationController, socialViewNavigationController...

    // I don't know what this does.
    [self tabBarConfig];

    // Add the tab bar controller to the window.
    [self.window addSubview:self.tabBarController.view];

    [self.window makeKeyAndVisible];

    return YES;
}

这里是苹果的官方文档用于 UINavigationController

UINavigationController is a stack of view controllers. Every view controller has a property called as navigationController, which represents the UINavigationController to which it belongs. Thus, if a view controller doesn't belong to a UINavigationController (in other words, if a view controller is not present in a stack), it's navigationController property would be nil.

If you want to have a view controller from which you could push new view controllers and pop view controllers, you need to create a stack (UINavigationController) first, push your view controller in this stack. Now since stack exists, we can keep pushing new view controllers in this stack.

Your bigPhotoView is not getting pushed probably because there is no UINavigationController existing for the current view controller (from which you are trying to push bigPhotoView). This could be verified as follows:

if (self.navigationController != nil) {
    [self.navigationController pushViewController:bigPhotoView animated:YES];
}

In the above case, you might not enter the if statement.

I prepared your function briefly. It looks something like this.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Create Start view controller.
    StartViewController *startController = [[StartViewController alloc] init];
    UINavigationController *startViewNavigationController = [[UINavigationController alloc] initWithRootViewController:startController];
    [startController release];

    // Similarly create for photos, videos and social...

    // Create an array of view controllers.
    NSArray* controllers = [NSArray arrayWithObjects:startViewNavigationController, photosViewNavigationController, videosViewNavigationController, socialViewNavigationController, nil];

    // Create our tab bar controller.
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];

    // Set the view controllers of the tab bar controller.
    self.tabBarController.viewControllers = controllers;

    // Release the startViewNavigationController, photosViewNavigationController, videosViewNavigationController, socialViewNavigationController...

    // I don't know what this does.
    [self tabBarConfig];

    // Add the tab bar controller to the window.
    [self.window addSubview:self.tabBarController.view];

    [self.window makeKeyAndVisible];

    return YES;
}

Here is the official apple's documentation for UINavigationController

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