在选项卡栏控制器类型应用程序中切换 UIViewController
请原谅这个简单的问题,但我正在绞尽脑汁地试图掌握 iPhone 的导航功能。
因此,我有一个带有 UITabBar 和 3 个 UITabBarItems 的选项卡栏控制器类型应用程序。我有第一个选项卡栏项目加载一种“主屏幕/欢迎”,在主屏幕上有一个按钮。当用户单击按钮时,我想打开一个不同的 UIViewController (LoginViewViewController) 以允许该人登录。
我基本上试图切换 UIViewController,然后当他们成功登录时,我想更改 TabBarItems。
这是我在连接到第一个 TabBarItem 的 ViewController 上的 .m 文件中的代码:
#import "LaunchViewViewController.h"
#import "LoginViewViewController.h"
@implementation LaunchViewViewController
@synthesize myLoginViewViewController;
- (IBAction)cmdRSVP_Click:(id)sender {
//Try #1
//[self addSubview:myLoginViewViewController.view];
//Try #2
//[[self navigationController] pushViewController:myLoginViewViewController animated:YES];
//Try #3
//LoginViewViewController *myLoginViewViewController2 = [[LoginViewViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
//[self.navigationController pushViewController:myLoginViewViewController2 animated:YES];
//[myLoginViewViewController2 release];
//myLoginViewViewController2 = nil;
//Try #4
//This just changes my screen to all White (expect the TabBarNavigationController
//[self.view removeFromSuperview];
//[self.view insertSubview:self.myLoginViewViewController.view atIndex:0];
// This displays without issue.
[self displayMessage:@"RSVP Clicked":@"Switch to Login View"]; }
正如您所看到的,我尝试了在各种教程中看到的 4 种不同方法。
在尝试 1、2、3 中:没有任何反应(没有崩溃或异常),但仍然显示警报消息框。
在尝试 4 中,选项卡栏控制器上方的屏幕区域变为白色并显示警报消息,但它从未显示我的其他 ViewController。
任何让我走上正轨的帮助都会很棒!
提前致谢! 贾森
Pardon the simple question, but I am pulling my hair out trying to get a grip around navigation in the iPhone.
So, I have a Tab Bar Controller type application with UITabBar and 3 UITabBarItems. I have the 1st Tab Bar Item loading a kind of "Home Screen/Welcome", on the Home Screen, there is a button. When the user clicks the button, I want to open a different UIViewController (LoginViewViewController) to allow the person to login.
I am trying to basically, switch UIViewController and then when they have successfully logged in, I want to change the TabBarItems.
This is the code that I have in the .m file on the ViewController that is connected to the 1st TabBarItem:
#import "LaunchViewViewController.h"
#import "LoginViewViewController.h"
@implementation LaunchViewViewController
@synthesize myLoginViewViewController;
- (IBAction)cmdRSVP_Click:(id)sender {
//Try #1
//[self addSubview:myLoginViewViewController.view];
//Try #2
//[[self navigationController] pushViewController:myLoginViewViewController animated:YES];
//Try #3
//LoginViewViewController *myLoginViewViewController2 = [[LoginViewViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
//[self.navigationController pushViewController:myLoginViewViewController2 animated:YES];
//[myLoginViewViewController2 release];
//myLoginViewViewController2 = nil;
//Try #4
//This just changes my screen to all White (expect the TabBarNavigationController
//[self.view removeFromSuperview];
//[self.view insertSubview:self.myLoginViewViewController.view atIndex:0];
// This displays without issue.
[self displayMessage:@"RSVP Clicked":@"Switch to Login View"]; }
As, you can see, I have tried 4 different ways that I have seen in various tutorials.
In try 1, 2, 3: Nothing happens (no crash or exception), but the Alert Message box is still displayed.
In try 4, the screen area above the Tab Bar Controller changes to White and the Alert Message is displayed, but it never shows my other ViewController.
Any help getting me on track would be great!!!
Thanks in advance!
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我根据我问的另一个问题弄清楚了这一点。
问题是我需要将 UINavigation 控制器连接到选项卡栏项(而不是 UIViewController)。 UIViewController 将成为 UINavigation 控制器的 RootViewController,这将允许我使用 pushViewController 和 popViewController 方法。
注意:这是帮助我解决此问题的问题的链接:
TableView 不会切换到详细信息连接到标签栏控制器时查看
Jason
I was able to figure this out based on another question that I asked.
The issue was that I needed to have a UINavigation controller connected to the Tab Bar Item (not a UIViewController). The UIViewController would then be the RootViewController of the UINavigation controller, which would then allow me to use the pushViewController and popViewController methods.
NOTE: This is the link to the question that helped me resolve this question:
TableView Does NOT Switch to Detail View When Connected to Tab Bar Controller
Jason