iPhone:Tabbar hides when pushing from TableView to UIViewController - iphone

I have four Tab bar items in a Tab bar which is being bottom of the view where i have the TableView. I am adding Tab bar and items programmatically (Refer below code) not through I.B.
Click on first three Tab bar items, will show the data in the same TableView itself. But clicking on last Tab bar items will push to another UIViewcontroller and show the data there. The problem here is, when i push to the viewController when clicking on last Tab bar item, main "Tab bar" is getting removed.
Tab bar code:
UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 376, 320, 44)];
item1 = [[UITabBarItem alloc] initWithTitle:#"First Tab" image:[UIImage imageNamed:#"first.png"] tag:0];
item2 = [[UITabBarItem alloc] initWithTitle:#"Second Tab" image:[UIImage imageNamed:#"second.png"] tag:1];
item3 = [[UITabBarItem alloc] initWithTitle:#"Third Tab" image:[UIImage imageNamed:#"third.png"] tag:2];
item4 = [[UITabBarItem alloc] initWithTitle:#"Fourth Tab" image:[UIImage imageNamed:#"fourth.png"] tag:3];
item5 = [[UITabBarItem alloc] initWithTitle:#"Fifth Tab" image:[UIImage imageNamed:#"fifth.png"] tag:4];
NSArray *items = [NSArray arrayWithObjects: item1,item2,item3,item4, item5, nil];
[tabBar setItems:items animated:NO];
[tabBar setSelectedItem:item1];
tabBar.delegate=self;
[self.view addSubview:tabBar];
Push controller code clicking from last Tab bar item:
myViewController = [ [MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
myViewController.hidesBottomBarWhenPushed=NO;
[[self navigationController] pushViewController:myViewController animated:NO];
I am not seeing bottom Tab bar when i push my current TableView to myViewController. I am seeing full screen view there. I want to see bottom Tab bar always when every tab item clicked.
What might be the problem here? Could someone who come across this issue, please share your suggestion to me?
Thank you.

You are using the TabBar itself (as view) as the main view initially.
Use UITabBarController like this:
//tabBarController is defined in the interface (the .h file)
tabBarController = [[UITabBarController alloc]init];
firstViewController = [[UIViewController alloc] init];
UITabBarItem *item1 = [[[UITabBarItem alloc]initWithTitle:#"First" image:nil tag:1] autorelease];
[firstViewController setTabBarItem:item2];
secondViewController = [[SecondViewController alloc]init];
UITabBarItem *item2 = [[[UITabBarItem alloc]initWithTitle:#"Sec" image:nil tag:1] autorelease];
[secondViewController setTabBarItem:item2];
//init the tab bar controller populated with two view controllers
[tabBarController setViewControllers:[NSArray arrayWithObjects:firstViewController,secondViewController,nil] animated:NO];
[window addSubview:tabBarController.view];

Related

Titles are not showing in the navigation bar iphone app

Titles are not showing after the home screen. I have put UITabBarController after the first screen. First screen hasn't got a UITabBarController. I am not sure the way I have implemented the tab.
I have set titles in every view controller by self.title = #"title". Titles are showing in tab items properly.
AppDelegate.m:
UIViewController *loginView= [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
UINavigationController *loginViewNavController = [[UINavigationController alloc] initWithRootViewController:loginView ];
self.navigationController = loginViewNavController;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
LoginViewController.m:
-(IBAction)navigateMainMenu:(id)sender{
tabBarController = [[UITabBarController alloc] init];
MyAccountsViewController *vc1 = [[MyAccountsViewController alloc] initWithNibName:#"MyAccountsViewController" bundle:nil];
DepositsViewController *vc2 = [[DepositsViewController alloc] initWithNibName:#"DepositsViewController" bundle:nil];
MoreViewController *vc3 = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
PayTransViewController *vc4 = [[PayTransViewController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects:vc1,vc4, vc2, vc3, nil];
tabBarController.viewControllers = controllers;
[self.navigationController pushViewController:tabBarController animated:YES];
[mainMenuViewController release];
If you set self.title = #"Title". This title will set in navController title. But In your TabBarController, every items are ViewController. Not an navigationController.
Issue: What you release in this line
[mainMenuViewController release];
mostly display title with bellow trickes :-
1. Self.title=#"Your Titile";
2. self.navigationItem.title=#"your Title";
3. when you using UItabBarController you can set Particular Viewcontroller as par your code Title like:-
vc1.title=#"your Title";
vc2.title=#"your Title";
vc3.title=#"your Title";
vc4.title=#"your Title";
I suggest you not you use tabbarcontroller inside a navigationcontroller. If you are using tabbarcontroller it should be the rootViewcontroller.

How to set Tabbar integration in iPhone?

I am working on an iPhone app, using UITabBar to develop it. Only the second tabbar title visible in tabbar, but first tabbar title not show in tabbar, how to fix this? please help me,
Thanks in Advance.
below is the source code for your reference.
NSMutableArray *items = [[NSMutableArray alloc]init];
tab =[[UITabBar alloc]initWithFrame:CGRectMake(0, 300, 320, 44)];
[self.tabBarItem initWithTitle:#"sample1" image:nil tag:111];
[items addObject:self.tabBarItem];
[self.tabBarItem initWithTitle:#"sample2" image:nil tag:101];
[items addObject:self.tabBarItem];
[tab setItems:items animated:YES];
[self.view addSubview:tab];
Dont navigate the view controllers, because then your controller which contains the TabBar will get popped out.
When we use UITabBar we dont use navigation in this way.
Just addSubView the new controllers with such frame so that your TabBar will alwaz be visible.
You have to add that tabbarItem in UITabBar.
NSArray *items = [[NSArray alloc]init];
[items addObject:self.tabBarItem]; //add all your tabBarItems in an array
[tab setItems:items animated:YES]; //then set all your tabBarItems in UITabBar like this
Actually you are using same instance of tabBarItem thats'y you are getting only second button.
Do this way, and Please if this helps you then accept the answer.
UITabBar *tabBar = [[UITabBar alloc]initWithFrame:CGRectMake(0, 725, 768, 49)];
NSMutableArray *items = [[NSMutableArray alloc]init];
UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:#"first" image:nil tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:#"second" image:nil tag:2];
UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:#"third" image:nil tag:3];
UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:#"fourth" image:nil tag:4];
[items addObject:item1];
[items addObject:item2];
[items addObject:item3];
[items addObject:item4];
[tabBar setItems:items];
[self.view addSubview:tabBar];
That's not the way you do to create and add a TabBar programmatically.
You'd rather use this other method: https://stackoverflow.com/a/3844365/655221
Good luck.

Creating uitabbarcontroller programmatically

I want to create uitabbarviewcontroller programmatically for my application.
In that uitabbarcontroller, i want to add 2 buttons namely "Show Log", "My Contacts".
when tapping on that "ShowLog" button , i want to push new view and the same for "My Contacts" button also
I dont know how to do that
Please help me below is the code i have tried
myTabBarController = [[UITabBarController alloc] init];
myTabBarController.view.frame = CGRectMake(0, 0, 320, 460);
MyCallLogViewController *testVC = [[MyCallLogViewController alloc] init];
TemplateViewController *otherVC = [[TemplateViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:testVC, otherVC, nil];
myTabBarController.viewControllers = controllers;
// Add the tab bar controller's current view as a subview of the window
[self.view addSubview:myTabBarController.view];

Setting custom UITabBarItem programmatically?

In iOS, the TabBar property in the TabBarController is read only. How can I associate a custom item with a particular view controller? How do I access the UITabBarItems inside the tabBar?
Like this
CustomView *custom = [[CustomView alloc] init];
UITabBarItem *customTab = [[UITabBarItem alloc] initWithTitle:#"Custom" image:[UIImage imageNamed:#"custom.png"] tag:0];
SecondView *second = [[SecondView alloc] init];
UITabBarItem *secondTab = [[UITabBarItem alloc] initWithTitle:#"Next" image:[UIImage imageNamed:#"next.png"] tag:1];
NSArray *views = [NSArray arrayWithObjects:custom,second,nil];
[tabBarController setViewControllers:views];
//how do I set the individual TabBarItems (customTab,secondTab) to be associated
//with the views in question? tabBarController.tabBar is read only
Inside each view controller, you can set a tabBarItem property. If the view controller is owned by a UITabBarViewController the associated item on the tab bar will be updated accordingly.
Something like this
-(void)viewDidLoad {
[super viewDidLoad];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTitle:yourTitle image:yourIcon tag:yourTag];
[self setTabBarItem:tbi]
[tbi release];
}
You are not restricted to perform this operation in the viewDidLoad method, obviously.

How to push to new view controller from modal view that implements UITabBarController

A view is presented modally:
[self presentModalViewController:modalNavController animated:YES];
This view uses a UITabBarController with 4 elements. One of these elements, "Info" has a button that's only visible if its available. If the button is clicked, it needs to push to another view controller, but I'd also like to maintain the tab bar from it's parent view. I haven't been able to figure out how to do this with or without keeping the tab bar. Ive tried pushing and presentingModally in all the places that I could image. How should this be done properly?
Creating tab bar:
infoController.title = #"Info";
streetViewController.title = #"Street View";
reviewController.title = #"Reviews";
streetViewController.tabBarItem.image = [UIImage imageNamed:#"flag.png"];
infoController.tabBarItem.image = [UIImage imageNamed:#"openMarker.png"];
reviewController.tabBarItem.image = [UIImage imageNamed:#"reviews.png"];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
UINavigationController *infoNC = [[[UINavigationController alloc] initWithRootViewController:infoController] autorelease];
infoNC.navigationBarHidden = YES;
[tabBarController setViewControllers:
[NSArray arrayWithObjects:infoNC, streetViewController, reviewController, nil]];
[self.view addSubview:tabBarController.view];
When you add the view controllers to the tab bar controller you need to do this:
MyCustomViewController *vc1 = [[MyCustomViewController alloc] initWithNibName:nil bundles:nil];
UINavigationController *nc1 = [[[UINavigationController alloc] initWithRootViewController:recipesRootView] autorelease];
[vc1 release];
then add nc1 instead of your custom view.
Then in MyCustomViewController to push another view controller do:
[self.navigationController pushViewController:(UIViewController *)page animated:YES];
That should work for you, and keep the tab bar controller.