iPhone - 如何将导航控制器添加到视图?

发布于 2024-11-06 22:22:58 字数 1527 浏览 4 评论 0原文

我当前有一个执行以下操作的应用程序:

S:加载视图作为登录屏幕。

a:如果登录成功,我将添加一个条款和条件屏幕作为子视图

b:如果不成功,我将添加一个注册表单作为子视图

F:< /strong> 然后,我在 a 或 b 成功时加载应用程序的主要部分,这是应用程序的一部分,其中有导航控制器和选项卡栏控制器。这是在 MainWindow.xib 中设置的

Sab 也有导航栏,但没有导航控制器,因为我认为我不会需要登录屏幕上的导航控制。

但事实证明我确实如此,我希望能够从 ab 向后导航到初始登录屏幕。

我尝试了多种方法来执行此操作,包括尝试以下答案:

如何在iPhone中的基于视图的应用程序中添加导航控制器?

你如何正确设置辅助视图以支持 iPhone 上的导航控制器?

如何以编程方式添加导航控制器?

但它们都不适合我,它们显示新的导航控制器位于登录屏幕上,并且不加载 a 或 b 屏幕。

我猜这是因为我将它们作为子视图添加到我的登录视图中,这不是正确的方法?我的代码如下:

 if(self.tcSubViewController == nil){

        TCSubViewController *_tcSubViewController = [[TCSubViewController alloc] initWithNibName:@"T&CView" bundle:[NSBundle mainBundle]];

        self.tcSubViewController = _tcSubViewController;

        [_tcSubViewController release];

    }
 [self.view addSubview:[tcSubViewController view]];

我猜我的登录流程存在根本缺陷?我应该能够完全删除 LoginView,然后显示条款和条件视图,而不必将其添加为子视图,不是吗?

I currently have an application that does the the following:

S: Loads a view as a login screen to start with.

a: If login is successful I add a terms and conditions screen as a subview

b: If not successful I add a sign up form as a subview

F: Then I load the main part of my app on success of either of the a or b which is the part of the app where there is a navigation controller and a tab bar controller. This is set up in MainWindow.xib

S, a and b also have Nav bars but no navigation controllers as I didn't think I would need navigation control on the login screens.

However it turns out I do, I want to be able to have back navigation from both a and b to the initial login screen.

I have tried several ways of doing this including trying the following answers:

How to add navigation controller in View Based Application in iPhone?

How do you properly set up a secondary view to support a navigation Controller on the iPhone?

how to add navigation controller programatically?

But none of them work for me, they display the new Navigation controller over the login screen and dont load the a or b screens.

I'm guessing this is because I am adding them as subviews to my loginView and this is not the correct way to do this? My code is as follows:

 if(self.tcSubViewController == nil){

        TCSubViewController *_tcSubViewController = [[TCSubViewController alloc] initWithNibName:@"T&CView" bundle:[NSBundle mainBundle]];

        self.tcSubViewController = _tcSubViewController;

        [_tcSubViewController release];

    }
 [self.view addSubview:[tcSubViewController view]];

I'm guessing there's a fundamental flaw in the way my Login flows? I should be able to completely remove the LoginView and then display the Terms and conditions view without having to add it as subview, shouldn't I?

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

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

发布评论

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

评论(2

您需要关闭导航控制器才能返回。
要关闭模态视图:

1.简单的方法:在模态视图中调用关闭的某些方法中只需添加:

[self.navigationController DismissModalViewControllerAnimated:YES];

2.更复杂的方法:在模态视图上实现和委托协议,并使呈现模态视图的视图控制器成为它的委托。并在委托方法中关闭模态视图。当我需要将数据从模式视图发送到呈现它的控制器时,我会这样做。

参考这篇文章

You need to dismiss the navigation controller to go back to.
To dismiss modal view:

1.Easy way: In your modal view in some method that you call to dismiss just add:

[self.navigationController dismissModalViewControllerAnimated:YES];

2.More complex way: Implement and delegate protocol on your modal view and make the view controller that presents the modal view the delegate of it. And in the delegate method dismiss the modal view. I do this way when I need to send data from modal view to the controller that present it.

Reference to this post

你的往事 2024-11-13 22:22:58

导航控制器的理念是,您只添加 navigationController.view 作为 UIWindow 子视图,它将自行管理其余部分。您只需要推送/弹出视图控制器,它们相应的视图就会自动从屏幕上添加/删除。

我当前应用程序的示例代码:

HomeController *homeController = [[[HomeController alloc] init] autorelease];
self.controller = [[[UINavigationController alloc] initWithRootViewController:homeController] autorelease];
self.controller.navigationBarHidden = YES;
[self.window addSubview:self.controller.view];
[self.window makeKeyAndVisible];

然后要推送下一个视图,您只需添加下一个控制器:

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

Navigation controller philosophy is that you add only navigationController.view as UIWindow subview and it wil manage the rest by itself. You only need to push/pop viewControllers and their corresponding views will be added/removed from screen automatically.

sample code from my current application:

HomeController *homeController = [[[HomeController alloc] init] autorelease];
self.controller = [[[UINavigationController alloc] initWithRootViewController:homeController] autorelease];
self.controller.navigationBarHidden = YES;
[self.window addSubview:self.controller.view];
[self.window makeKeyAndVisible];

and then to push next view you just add next controller:

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