Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to use TabBar in viewbase application

Hi,
i have an application which is an viewbase application. now i have to add a tabbar at the bottom.
problem is this, that all tutorials i found on net are on navigation base application. so can i implement tabbar in viewbase application. If yes then How???

Muhammad Usman Aleem

iPhone OS 3.0

Posted on Jul 30, 2009 11:00 PM

Reply
29 replies

Aug 23, 2010 5:01 PM in response to PalNor

Hi PalNor, and welcome to the Dev Forum!

I'm having some difficulty following your code because I can't tell which identifiers refer to a class, and which refer to an object of that class. I would recommend making sure your identifiers follow the Obj-C convention of capitalizing the first letter of a class name, and beginning the identifier of an object with a lower case letter. For example:

@interface SecondViewController : UIViewController <UITabBarDelegate> {
// upper case // lower case
ActivityViewController *activityViewController;
WebViewController *webViewController;
UIViewController *currentViewController;
UITabBar *myTabBar;
}
@property (nonatomic, retain) ActivityViewController *activityViewController;
@property (nonatomic, retain) WebViewController *webViewController;
@property (nonatomic, assign) UIViewController *currentViewController;
@property (nonatomic, retain) IBOutlet UITabBar *myTabBar; // <-- connect to the tab bar in IB
@end

There are also several lines that don't make any sense. E.g.:

if (SecondViewController.ActivityViewController == nil) // ...

If the above is inside the @implementation of SecondViewController, you would refer to the activityViewController instance variable as 'self.activityViewController' (assuming the identifier of that ivar starts with a lower case letter as shown in the @interface example). So I would expect that line to look like either of the following:

if (self.activityViewController == nil) // ...
// or:
if (activityViewController == nil) // ...

Most of the errors I see at first glance seem to be related to some confusion over the difference between a class and an instance of a class. There also seems to be some confusion over the view hierarchy. These are fundamental problems that will cause your program to fail regardless of how you're switching views. So if we can assist you further, I'd recommend starting your own thread. In that case, please include SecondViewController.h, as well as another copy of SecondViewController.m which is properly formatted.

To format your code please refer to the announcement which is the first topic of the forum. You can see how your post will appear by clicking on the Preview tab above the Reply editor panel.

- Ray

Nov 30, 2010 7:50 PM in response to dennylee60

I just got a question : the solution proposed in the testtab_raynewbie doesn't work properly in fact : you cant remark that everything goes well as long as you don't click on the same tab twice (or more), in which case the second (and all others) nib loaded is the nib "implementing" the tabbar, and not the nib designing the tab. So that in fact the proposed solution is not a solution. And can we slightly modify this to make it work properly ? Thx

Dec 1, 2010 1:25 PM in response to ssalminen

I just got a question : the solution proposed in the testtab_raynewbie doesn't work properly in fact : you cant remark that everything goes well as long as you don't click on the same tab twice (or more), in which case the second (and all others) nib loaded is the nib "implementing" the tabbar, and not the nib designing the tab. So that in fact the proposed solution is not a solution. And can we slightly modify this to make it work properly ? Thx

Jan 26, 2011 5:35 PM in response to MUsman

Thank you so much for this code! but I am having one simple problem I just cannot figure out.
I do not know how to return to my original view after visiting the tab bar view. I have tried to use the following code in my tab's view controllers but I can't get it to work.

-(IBAction) toHome{
[self dismissModalViewControllerAnimated:YES];

}

-(IBAction) toHome{
testtabViewController *screen = [[testtabViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
[screen release];
}


This is usually what I use to navigate nib files but the first code doesn't have any effect at all, and the second code returns to the main screen while remaining within the tab bar. How can I fix this?
-Thanks

Mar 30, 2011 12:21 PM in response to MUsman

Hi Dev Forum!

I tried the code from the solution and i also get the views mixed up. Its like it doesn't clear the screen at all. I know this is a pretty old thread but I really need to be able to mix tab navigation in a view based project I'm working on and i can't find much usable info out on the web about this. So if anyone has a way to fix this solution so it works or if anyone know of a better way to add a working tab bar to a view based application i would be very grateful!

Best Regards

Bjorn S

Jan 17, 2012 2:28 AM in response to Slaaphoofd

I have used this solution and ran into a problem with the view loading below my tabBar but on top of the naviagation toolbar at the top of the screen. This was fixed by modifying your code to read


[self.view insertSubview:tab1ViewController.view belowSubview:_toolbar];


However I have now run into problems with rotation of the device. I am trying to add the tabBar into the details view of a splitViewController. Like I said everything seems to be good except the rotation.


I have created a new question at the following if anyone has a solution?


https://discussions.apple.com/thread/3660615


Message was edited by: mattgolding Put the code inside a code block

Mar 27, 2012 3:10 PM in response to MUsman

No it didn't seem to work.


The tabbar item doesn't get the badge.


I also tried this in the viewdidload


UITabBarItem *tbi=(UITabBarItem *)[_tabBarController.tabBar.items objectAtIndex:1];

tbi.badgeValue="2";


No syntax error, but just doesn't work. I am using the method outlined in page 1 to add a tab bar.


in my .h file.

@interface mycontroller: UIViewController <UITabBarDelegate>

{

..define lots of stuff

}

How to use TabBar in viewbase application

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.