使用Tab Bar和Nav Bar提供建议

时间:2023-01-30 17:27:19

I'd just like to clear something up..

我只想澄清一些事情......

I have an app where the Main Window UI has a Tab bar with 3 tabs (opt1, opt2, op3). Each opt has its own xib file where i've drawn their own interfaces.

我有一个应用程序,主窗口UI有一个标签栏,有3个标签(opt1,opt2,op3)。每个opt都有自己的xib文件,我在其中绘制了自己的接口。

In my app delegate class I have included a UITabBar *rootController, and hooked this up to my tab bar in my Main Window xib file.

在我的app委托类中,我已经包含了一个UITabBar * rootController,并将其连接到我的主窗口xib文件中的标签栏。

Now.. In the Tab bar, I have dragged in 3 navigation controllers (1 for each opt) and inside each one I have a 1) tab bar icon, 2) navigation bar and 3) view controller.

现在..在标签栏中,我拖动了3个导航控制器(每个选项1个),每个内部我有1)标签栏图标,2)导航栏和3)视图控制器。

Back in my app delegate.h class I have included code for UINavigationController *nav1, nav2, nav3..and hooked these up accordingly in IB in MainWindow.xib (TabBar->navController1, navController2, navController3).

回到我的应用程序delegate.h类中,我已经包含了UINavigationController * nav1,nav2,nav3 ...的代码,并在MainWindow.xib中的IB中相应地将它们连接起来(TabBar-> navController1,navController2,navController3)。

Is this the right way to do it? Also how can I make use of these nab bars in my opt1, opt2, opt3 class files?

这是正确的方法吗?另外我如何在opt1,opt2,opt3类文件中使用这些nab条?

here is my code: app delegate.h

这是我的代码:app delegate.h

#import <UIKit/UIKit.h>

@class LoginViewController;

@interface myAppDelegate : NSObject <UIApplicationDelegate>
{

UIWindow *window;
UINavigationController *navigationController1, *navigationController2,     *navigationController3;
IBOutlet UITabBarController *rootController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController1, *navigationController2, *navigationController3;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;

@end

appdelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
[window addSubview:[rootController view]]; 
[window makeKeyAndVisible];

LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
[self.rootController presentModalViewController:loginViewController animated:NO];

}

Then in my LoginController.m class , when the user enters correct credentials I call

然后在我的LoginController.m类中,当用户输入正确的凭据时,我调用

[self dismissModalViewControllerAnimated:YES];

In my MainWindow.xib, I hook up my rootController to a TabBarController. In the TabBarController I have put 3 NavigationControllers inside it and linked them to 3 tabOption classes which each have their own .xib view.

在我的MainWindow.xib中,我将rootController连接到TabBarController。在TabBarController中,我在其中放置了3个NavigationControllers并将它们链接到3个tabOption类,每个类都有自己的.xib视图。

The tab bar switches between the 3 option views nicely. However in 1 .xib view I have a button to open a new .xib. So in my tabOption1 class I have the following:

标签栏可以很好地在3个选项视图之间切换。但是在1 .xib视图中,我有一个按钮来打开一个新的.xib。所以在我的tabOption1类中,我有以下内容:

-(IBAction)openBook:(id)sender{

UIViewController *nextVC = [[PageViewController alloc] initWithNibName:@"PageView" bundle:nil];
[self.navigationController pushViewController:nextVC animated:YES];
}

However this does not open up my PageView.xib... I have connected it to my PageViewController class and everything too..and the button works because I've tested it with a UIDialog

然而,这并没有打开我的PageView.xib ...我已将它连接到我的PageViewController类,而且所有内容都是......并且按钮有效,因为我用UIDialog测试了它

2 个解决方案

#1


1  

Have you seen the Apple Programming Guides? They might give you a better understanding of how everything ties together - you could start here:

你看过Apple编程指南了吗?他们可能会让你更好地理解一切如何联系在一起 - 你可以从这里开始:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40007457-CH103-SW1

In answer to your question, that looks like an OK way of setting up. I really would recommend reading up a bit though :)

在回答你的问题时,这看起来像是一种可靠的设置方式。我真的会建议读一点虽然:)

#2


0  

In response to your comment, that looks like a reasonable way to do what you're trying to achieve. If it works, then it works.

在回应您的评论时,这似乎是一种合理的方式来做您想要实现的目标。如果它工作,那么它的工作原理。

In response to your other issue then you can get the navigation controller object by doing this: self.navigationController

为了回应您的其他问题,您可以通过以下方式获取导航控制器对象:self.navigationController

So you can "go to" a new view controller like this:

所以你可以“转到”这样一个新的视图控制器:

// make the view controller
UIViewController *nextVC = [[MyCustomViewController alloc] initWithNibName:@"MyCustomViewController" bundle:nil];

// push it onto the navigation stack
[self.navigationController pushViewController:nextVC animated:YES];

To add this to the click event on a button you need to create the button in interface builder and create an IBAction in your code. The IBAction might look like this:

要将其添加到按钮上的单击事件,您需要在界面构建器中创建按钮并在代码中创建IBAction。 IBAction可能如下所示:

- (IBAction)pushNextViewController:(id)sender {
  UIViewController *nextVC = [[MyCustomViewController alloc] initWithNibName:@"MyCustomViewController" bundle:nil];
  [self.navigationController pushViewController:nextVC animated:YES];
}

Then you need to link to it from interface builder. I'm not sure how to do this, I generally don't use interface builder, and certainly haven't used it since about XCode 3.

然后,您需要从界面构建器链接到它。我不知道如何做到这一点,我通常不使用界面构建器,当然也没有使用它,因为关于XCode 3。

To do it programatically you can use this method:

要以编程方式执行此操作,您可以使用此方法:

[MyButton addTarget:self selector:@selector(pushNextViewController:) forControlEvents:UIControlEventTouchUpInside]; // always use touch up inside

Keywords to look up to help you find tutorials and stuff on the internet: ibaction uinavigationcontroller pushviewcontroller:animated: popviewcontrolleranimated:

要查找的关键字,以帮助您在互联网上找到教程和东西:ibaction uinavigationcontroller pushviewcontroller:animated:popviewcontrolleranimated:

#1


1  

Have you seen the Apple Programming Guides? They might give you a better understanding of how everything ties together - you could start here:

你看过Apple编程指南了吗?他们可能会让你更好地理解一切如何联系在一起 - 你可以从这里开始:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40007457-CH103-SW1

In answer to your question, that looks like an OK way of setting up. I really would recommend reading up a bit though :)

在回答你的问题时,这看起来像是一种可靠的设置方式。我真的会建议读一点虽然:)

#2


0  

In response to your comment, that looks like a reasonable way to do what you're trying to achieve. If it works, then it works.

在回应您的评论时,这似乎是一种合理的方式来做您想要实现的目标。如果它工作,那么它的工作原理。

In response to your other issue then you can get the navigation controller object by doing this: self.navigationController

为了回应您的其他问题,您可以通过以下方式获取导航控制器对象:self.navigationController

So you can "go to" a new view controller like this:

所以你可以“转到”这样一个新的视图控制器:

// make the view controller
UIViewController *nextVC = [[MyCustomViewController alloc] initWithNibName:@"MyCustomViewController" bundle:nil];

// push it onto the navigation stack
[self.navigationController pushViewController:nextVC animated:YES];

To add this to the click event on a button you need to create the button in interface builder and create an IBAction in your code. The IBAction might look like this:

要将其添加到按钮上的单击事件,您需要在界面构建器中创建按钮并在代码中创建IBAction。 IBAction可能如下所示:

- (IBAction)pushNextViewController:(id)sender {
  UIViewController *nextVC = [[MyCustomViewController alloc] initWithNibName:@"MyCustomViewController" bundle:nil];
  [self.navigationController pushViewController:nextVC animated:YES];
}

Then you need to link to it from interface builder. I'm not sure how to do this, I generally don't use interface builder, and certainly haven't used it since about XCode 3.

然后,您需要从界面构建器链接到它。我不知道如何做到这一点,我通常不使用界面构建器,当然也没有使用它,因为关于XCode 3。

To do it programatically you can use this method:

要以编程方式执行此操作,您可以使用此方法:

[MyButton addTarget:self selector:@selector(pushNextViewController:) forControlEvents:UIControlEventTouchUpInside]; // always use touch up inside

Keywords to look up to help you find tutorials and stuff on the internet: ibaction uinavigationcontroller pushviewcontroller:animated: popviewcontrolleranimated:

要查找的关键字,以帮助您在互联网上找到教程和东西:ibaction uinavigationcontroller pushviewcontroller:animated:popviewcontrolleranimated: