I'm trying to put a TTThumbsViewController inside a UITabBarController, but when I do, the TTThumbsViewController's NavigationBar doesn't show. There is just blank space where the NavigationBar should be. I've loaded just the TTThumbsViewController by itself, and the NavigationBar loads just fine. I'm sure I've just missed a setting, but I can't figure out what it is.
Here is what I'm doing to create the UITabBarController and the TTThumbsViewController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:#"Thumbs" image:[UIImage imageNamed:#"icon.png"] tag:Thumbs];
thumbsViewController.tabBarItem = thumbsTabBarItem;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:thumbsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
If you're loading the TTThumbsViewController from a UITabController, you need to create the UINavigationController yourself.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:#"Thumbs" image:[UIImage imageNamed:#"icon.png"] tag:Thumbs];
thumbsViewController.tabBarItem = thumbsTabBarItem;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:ThumbsViewController] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Related
The title pretty much says it all. I'm trying to create an interface where after connecting with Facebook, the window loads up my HomeViewController (my initially selected UITabBarItem). Although, I do not want the UINavigationBar that comes through as I have set the HomeViewController as the LoginViewController's root view. I have different navigation bar items for each view, so defaulting to that one won't work. I have this code now.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.mainViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navigationController;
}
Create your custom tabbar Class add it in appDelegate
appDelegate.m
self.tabBarVC = [[[TabBarVC alloc] init] autorelease];
self.navController = [[[UINavigationController alloc]initWithRootViewController:self.tabBarVC]autorelease];
self.window.rootViewController = self.navController;
TabBarVC.h
#import <UIKit/UIKit.h>
#interface TabBarVC : UITabBarController
#end
TabBarVC.m
#import "TabBarVC.h"
#import "ViewController1.h"
#import "ViewController2.h"
#implementation TabBarVC
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *vc1 = [[UIViewController alloc] initWithNibName:#"ViewController1" bundle:nil];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:#"ViewController2" bundle:nil];
[self setViewControllers:[NSArray arrayWithObjects:vc1,vc2, nil]];
}
#end
After a good nights sleep, I was able to figure it out. Hopefully, this can help others out there!
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
// Initialize view controllers
HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
ConnectViewController *connectViewController = [[ConnectViewController alloc] initWithNibName:#"ConnectViewController" bundle:nil];
PartyControlViewController *partyControlViewController = [[PartyControlViewController alloc] initWithNibName:#"PartyControlViewController" bundle:nil];
MeViewController *meViewController = [[MeViewController alloc] initWithNibName:#"MeViewController" bundle:nil];
MoreViewController *moreViewController = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:homeViewController, connectViewController, partyControlViewController, meViewController, moreViewController, nil]];
// Customize Tab Bar
UITabBarItem *homeTab = [[UITabBarItem alloc] initWithTitle:#"Home" image:nil tag:0];
UITabBarItem *connectTab = [[UITabBarItem alloc] initWithTitle:#"Connect" image:nil tag:1];
UITabBarItem *partyControlTab = [[UITabBarItem alloc] initWithTitle:#"Party Control" image:nil tag:2];
UITabBarItem *meTab = [[UITabBarItem alloc] initWithTitle:#"Me" image:[UIImage imageNamed:#"person.png"] tag:3];
UITabBarItem *moreTab = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:4];
[homeViewController setTabBarItem:homeTab];
[connectViewController setTabBarItem:connectTab];
[partyControlViewController setTabBarItem:partyControlTab];
[meViewController setTabBarItem:meTab];
[moreViewController setTabBarItem:moreTab];
self.window.rootViewController = self.tabBarController;
}
I was wondering if there is a tutorial or any hints for this tab bar customization, when you select a tab bar and hold you can change the icons to user liking sort of like this (check the bottom).
[TAB] http://tapbots.com/software/tweetbot/
Use UIGestures
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController1
UIViewController *viewController2 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController2
UIViewController *viewController3 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController3
UIViewController *viewController4 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController4
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
viewController4, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
see the customization of the tab-bar here
I want to make it translucent black, why doesn't this work?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UINavigationController *viewController1 = [[UINavigationController alloc] init];
viewController1.navigationBar.barStyle = UIBarStyleBlackTranslucent;
RSSViewController *rssViewController = [[RSSViewController alloc] init];
[viewController1 addChildViewController:rssViewController];
UIViewController *viewController2 = [[CalendarViewController alloc] initWithNibName:#"CalendarViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[self customizeInterface];
return YES;
}
When I put viewController1.navigationBar.barStyle = UIBarStyleBlackTranslucent; navigation items simply disappear...
Use this
viewController1.navigationBar.tintColor = [UIColor blackColor];
viewController1.navigationBar.translucent = YES;
I'm new in iPhone, I created application that is started with UITabbarController with 4 items using AppDelegate. through the app I opened some views and I want to relaunch the AppDelegate again by using a code like:
[appdelegate presentModalViewController:myNavController animated:YES];
is this possible?
this is in my AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSMutableArray *array = [[NSMutableArray alloc] init];
MaktabatyTableViewController *own = [[MaktabatyTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *ownNavController = [[UINavigationController alloc] initWithRootViewController:own];
[array addObject:ownNavController];
NewestTableViewController *newest = [[NewestTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *newestNavController = [[UINavigationController alloc] initWithRootViewController:newest] ;
[array addObject:newestNavController];
MostBuyTableViewController *mostbuy = [[MostBuyTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *mostbuyNavController = [[UINavigationController alloc] initWithRootViewController:mostbuy];
[array addObject:mostbuyNavController];
FreeBooksTableViewController *free = [[FreeBooksTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *freeNavController = [[UINavigationController alloc] initWithRootViewController:free];
[array addObject:freeNavController];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = array;
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window addSubview:self.tabBarController.view];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Thanks in advance.
I think you are looking for something like this..
A login screen which is a simple view with login fields, upon login, this screen is of no use. And the main app is based on tab bar.
And a Logout screen or A screen showing after user signed out.
I had this requirement in one of my app, so i made a sample template. May be it helps you checkout this.
I know I can do this
[self.navigationController pushViewController:self.someUITabBarController animated:YES];
And that means putting UITabBarController on a navigationgController somehow
What about if I want someUITabBarController to be the first controller (the one located on the lowest level) of navigationController?
I simply cannot change the rootViewController of the NavigationController into someUITabBarController
Erm not sure this is what you want. Below this code will be put under the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions in you "appDelegate" class.
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = ...
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1];
NSArray *controllers = [NSArray arrayWithObjects:navigationController, nil]; // can add more if you want
[tabController setViewControllers:controllers];
// this is for custom title and image in the tabBar item
navigationController.tabBarItem.title = #"abc";
[navigationController.tabBarItem setImage:[UIImage imageNamed:#"abc.png"]];
self.window.rootViewController = tabController; // or [self.window addSubview: tabController.view];
[self.window makeKeyAndVisible];
I am not sure if this works. But try this,
UINavigationController *navCont = [[UINavigationController alloc] init];
[navCont pushViewController:navCont animated:NO];