Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2009, 07:35 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 11
napoleone1981 is on a distinguished road
Default Items in uitabbar doesn't show properly

Hi to all,
I'm a newbie of Obj-C and Cocoa. After spending some days trying to build my first app using a TabBarController with IB I realize to make it programmatically (not all...).

Now I create the UITabBar at runtime (applicationDidFinishLaunching) and I made 4 xib for four view associated withe tabbar items.

Xib File's Owners are 4 different ViewController. Every Xib file contains a UITabBarItem associated with the tabBarItem outlet of the UIViewController (the file's owner)

The problem is that when the application loads, only the first item in the tabbar is visible, with the associated view, but the others not.
When I push where I suppose there's the other item, the tabbar item title is displayed with the associated view correctly.

How can I show all the tabbaritems when I load the application??

This is my application delegate code:
Code:
@synthesize window;
@synthesize tabBarController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
	tabBarController = [[UITabBarController alloc] init];
	NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:4];
	
	// Creo i 4 view controller
	FeaturedViewController *featured = [[FeaturedViewController alloc] initWithNibName:@"FeaturedView" bundle:nil];
	SecondViewController *second = [[SecondViewController	alloc] initWithNibName:@"SecondView" bundle:nil];
	HelpViewController *help = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil];
	SettingsViewController *settings = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
	
	// li aggiungo all'array locale di controller
	[controllers addObject:featured];
	[controllers addObject:second];
	[controllers addObject:help];
	[controllers addObject:settings];
	
	[featured release];
	[second release];
	[help release];
	[settings release];
	
	tabBarController.viewControllers = controllers;	
//	[[tabBarController viewControllers] addObjectsFromArray:controllers];
	[controllers release];
	
	// Aggiungo il tab controller alla window
	tabBarController.selectedIndex = 0;
	[window addSubview:[tabBarController view]];
    [window makeKeyAndVisible];
}
This is a screenshot when I first run the application (as you see, there's only one tabbaritem and not four...)
__________________
By,
N@poleone
napoleone1981 is offline   Reply With Quote
Old 03-16-2009, 07:55 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Atlanta
Posts: 411
funkytaco is on a distinguished road
Default

I think you need something like this:
Code:
tabController.viewControllers = [NSArray arrayWithObjects:featured,second,help,settings, nil];
instead of:

Code:
tabBarController.viewControllers = controllers;
I'm still learning, so let me know if this works out for you or not.
funkytaco is offline   Reply With Quote
Old 03-16-2009, 07:58 PM   #3 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

Quote:
Originally Posted by funkytaco View Post
I think you need something like this:
Code:
tabController.viewControllers = [NSArray arrayWithObjects:featured,second,help,settings, nil];
instead of:

Code:
tabBarController.viewControllers = controllers;
I'm still learning, so let me know if this works out for you or not.
do it in IB, if you're having trouble. It'll save you a lot of time.
meowmix23F is offline   Reply With Quote
Old 03-17-2009, 10:30 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 11
napoleone1981 is on a distinguished road
Default

Quote:
Originally Posted by meowmix23F View Post
do it in IB, if you're having trouble. It'll save you a lot of time.
Well, I'm trying programmatically because I found "some" problem with IB... ;-)


@funkytaco: I'll try later this evening when I'll be at home... but honestly, I don't see difference between my and your code...
__________________
By,
N@poleone
napoleone1981 is offline   Reply With Quote
Old 03-17-2009, 03:32 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 11
napoleone1981 is on a distinguished road
Default

Quote:
Originally Posted by funkytaco View Post
I think you need something like this:
Code:
tabController.viewControllers = [NSArray arrayWithObjects:featured,second,help,settings, nil];
instead of:

Code:
tabBarController.viewControllers = controllers;
I'm still learning, so let me know if this works out for you or not.
I've just tried... No good news... the problem is still there!

Any other help??
__________________
By,
N@poleone
napoleone1981 is offline   Reply With Quote
Old 05-15-2009, 09:08 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 24
S.LakshmiKanth Reddy is on a distinguished road
Default

Quote:
Originally Posted by napoleone1981 View Post
I've just tried... No good news... the problem is still there!

Any other help??
before adding the controller to the tabbar, assign title for each and every controller, ie., Featured, second,help,settings.

then add the controllers to the tab bar, it will work.
S.LakshmiKanth Reddy is offline   Reply With Quote
Old 09-19-2009, 09:12 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 1
hiptomorrow is on a distinguished road
Default I had the same problem

I had the same problem but after a wee bit of thought realised you have to use setTabBarItem in each of the view controllers when they're initialized...

Code:
//override the initialize method
-(id)init
{
	if(self = [super init]){
		
		//setup the tab bar item
		[self setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"YOUR TITLE" image:[UIImage imageNamed:@"yourimage.png"] tag:0]];			
	}
	
	return self;
}
Hope this helps :-)

I'm a novice at this, so if anyone can see any mistakes I've made, or a better way to do it, please correct me!
hiptomorrow is offline   Reply With Quote
Reply

Bookmarks

Tags
uitabbar, uitabbarcontroller, uitabbaritem

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 341
3 members and 338 guests
guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0