0

It might be simple but not able to find exact solution for this.i am using xcode 4.2.

I want to use Tab bar in one of the view in my application. i went through many tutorials all tutorials are related to navigation based application and other view based application.Even i understood how to add a tab bar controller in story board which is main view.

What i need is i have class called Homepage.h and .m and .xib which is subclass of UIViewController class.Again my class is not main class its added later for one of the view.So i want to add a tab bar and communicate with navigationBar and other views so how can i do it plz give me some samples.

Problem is i want to add Tab bar to the default UIView and communicate with navigation controller and other views. i dont want to drag Tab bar controller from utilities.Incase if i drag how can i make it view on moving from one view to another as i already have a Default UIview.Please give me links or any tutorials where i can add tab bar and switch between views using navigation controller.

NOTE: i am using Single View based Application

4

1 回答 1

1

取 AppDelegate.h 中的 UINavigationController 对象和 UITabBarController 对象

在 AppDelegate.h

   First *first;
   Second *second;
   Third *third;

UINavigationController *navController;

    UITabBarController *tabbar;

@property (nonatomic, 保留) UITabBarController *tabbar;

@property (nonatomic, 保留) UINavigationController *navController;

在 AppDelegate.m

@synthesize 标签栏,导航控制器;

在 ApplicationdidFinishLaunching

tabbar=[[UITabBarController alloc]init];

first=[[First alloc]initWithNibName:@"First" bundle:nil];
second=[[Second alloc]initWithNibName:@"Second" bundle:nil];
third=[[Third alloc]initWithNibName:@"Third" bundle:nil];

navController=[[UINavigationController alloc]initWithRootViewController:first];

NSArray *viewControllerArray=[[[NSArray alloc] initWithObjects:navController1,second,third,nil] autorelease];

[self.window addSubview:tabbar.view];

[tabbar setViewControllers:viewControllerArray];

[first setTitle:@"First"];

[second setTitle:@"Second"];

[third setTitle:@"Third"];

编写此代码,不需要将 Tabbar 放在 XIB 中。试试这个代码,它会帮助你。

于 2012-01-24T09:07:28.810 回答