iPhone - 如何将导航控制器添加到视图?
我当前有一个执行以下操作的应用程序:
S:加载视图作为登录屏幕。
a:如果登录成功,我将添加一个条款和条件屏幕作为子视图
b:如果不成功,我将添加一个注册表单作为子视图
F:< /strong> 然后,我在 a 或 b 成功时加载应用程序的主要部分,这是应用程序的一部分,其中有导航控制器和选项卡栏控制器。这是在 MainWindow.xib 中设置的
S、a 和 b 也有导航栏,但没有导航控制器,因为我认为我不会需要登录屏幕上的导航控制。
但事实证明我确实如此,我希望能够从 a 和 b 向后导航到初始登录屏幕。
我尝试了多种方法来执行此操作,包括尝试以下答案:
你如何正确设置辅助视图以支持 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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
导航控制器的理念是,您只添加 navigationController.view 作为 UIWindow 子视图,它将自行管理其余部分。您只需要推送/弹出视图控制器,它们相应的视图就会自动从屏幕上添加/删除。
我当前应用程序的示例代码:
然后要推送下一个视图,您只需添加下一个控制器:
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:
and then to push next view you just add next controller: