IPhone iOs 5, need help getting my tab bar at the top to work

Posted by Patrick on Stack Overflow See other posts from Stack Overflow or by Patrick
Published on 2012-07-07T15:12:04Z Indexed on 2012/07/07 15:15 UTC
Read the original article Hit count: 160

Filed under:
|
|
|
|

I wanted to have the tab bar at the top.

So i created a new project in XCode. Added a view and then inside that view i added (scrollbar, text and another view). See picture.

Storyboard view of the MainWindow. Top part is for the tab host, middle is for content and bottom is for copyright

What i wanted was to have my tab bar at the top. Then in the middle would be the contents from the tab bar and below it a small copyright text. See picture.

All controls that i have added in the StoryBoard

No idea how to make this correctly. I have tried to create the UITabBarController on the fly and then assign it into the view at the top. (Top white space on the picture dedicated for the tab bar).

Here is my code to init the MainWindow.

MainWindow.h

#import <UIKit/UIKit.h>

@class Intro;

@interface MainWindow : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *mainContentFrame;
@property (strong, nonatomic) IBOutlet UIView *mainTabBarView;
@property (strong, nonatomic) UITabBarController *mainTabBar;

@property (nonatomic, strong) Intro *intro; // Trying to get this tab to show in the tab bar

@end

MainWindow.m

#import "MainWindow.h"
#import "Intro.h"

@interface MainWindow ()

@end

@implementation MainWindow
@synthesize mainContentFrame = _mainContentFrame;
@synthesize mainTabBarView = _mainTabBarView;
@synthesize mainTabBar = _mainTabBar;

@synthesize intro = _intro;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    _intro = [[Intro alloc] init];
    NSArray *allViews = [[NSArray alloc] initWithObjects:_intro, nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    _mainTabBar = [[UITabBarController alloc] init];
    [_mainTabBar setViewControllers:allViews];

    [_mainTabBarView.window addSubview:_mainTabBar.tabBarController.view];
}

- (void)viewDidUnload
{
    [self setMainTabBar:nil];
    [self setMainContentFrame:nil];
    [self setMainContentFrame:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

What am i missing to get this to work? Wanted the content to end up in the scrollview so that all tabs are scrollable.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios