开发者

tab bar in a view based application on the fift view

hy there,

i have asked a similar question just 3 day ago, but it did not helped me out, so here i am again. I have made a VIEW based application so not a tab bar application, and i want to add a tabbar to it. In the developer library i read how you can do this http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html I was using the tutorial how to add a tabbar with a nib file. But there is only one problem with thi开发者_运维问答s the tab bar is created in the app delegate, and that is not what i want, i want my tabbar not on the main view but on the fift view.

Does anyone know a solution, on the internet i read something on how to do it with view didload, or something like that, but i could nog figure it out.

i hope someone can help me with this.

thanks any way.


I think i got the solution:

First change your view base application to a navigation based:
This is your standard template for you main nib:

tab bar in a view based application on the fift view

Make it like this:

tab bar in a view based application on the fift view

Add a UINavigationController. Open it and drag the ViewBasedViewController over the existing controller in your UINavigationController.

Go to your App Delegate:

@interface ViewBasedAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end

@synthesize window;
@synthesize navController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [self.window addSubview:navController.view];
    [self.window makeKeyAndVisible];

    return YES;


 }

//Other code omitted
@end

Link the navController outlet to the navigation controller in your NIB.

Make a new class with lets say 'TheTabBarController'.

Add this to your view based controller to add the fifth controller:

- (IBAction) addFifthView:(id)sender {
    TheTabBarController *conn = [[TheTabBarController alloc] init];
    [self.navigationController pushViewController:conn animated:YES];
    [conn release];
}

Implement the TheTabBarController like this:

@interface TheTabBarController : UITabBarController {

}

@end

@implementation TheTabBarController

- (void) viewDidLoad {
    UIViewController *dummy = [[UIViewController alloc] initWithNibName:@"Dummy" bundle:nil];
    dummy.title = @"Dummy title";
    dummy.view.backgroundColor = [UIColor redColor];

    UIViewController *otherDummy = [[UIViewController alloc] initWithNibName:@"Dummy" bundle:nil];
    otherDummy.title = @"Other dummy";
    otherDummy.view.backgroundColor = [UIColor blueColor];

    [self setViewControllers:[NSArray arrayWithObjects:dummy,otherDummy,nil]];

    [dummy release];
    [otherDummy release];
}
//Other code omitted
@end

Should work like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜