Why my navbar doesn't show up? - ios

I'm trying to set my window's root view controller to a UITabBarController with a UINavigationController but for some reason the navigation bar doesn't show up. Anybody knows why?
Thanks
Here is my method:
- (void) showUserOnlyScreen
{
UITabBarController *tabbarController = [[UITabBarController alloc]init];
SSHomeViewController *homeVC = [[SSHomeViewController alloc]init];
UINavigationController *homeNav = [[UINavigationController alloc]initWithRootViewController:homeVC];
[tabbarController setViewControllers:#[homeNav]];
self.window.rootViewController = tabbarController;
[self.window makeKeyAndVisible];
}

Your code is OK.
Check if the UINavigationBar is transparent by applying a border on it:
homeNav.navigationBar.layer.borderWidth = 2.0f;
homeNav.navigationBar.layer.borderColor = [UIColor redColor].CGColor;
Check also if you mistakenly hide the navigationbar on your SSHomeViewController controller with this:
[self.navigationController setNavigationBarHidden:YES animated:NO];

Related

How to display all tabBar titles in ios7

Basically i cant get to display all tabBar Items when i run my app, just the first view controller is displayed:
I literally have to click on a tab to display its Item:
This my code in Appdelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Initialize window
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
// Set background colors for both NavBar and TabBar
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.157 green:0.718 blue:0.553 alpha:1]];
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:0.141 green:0.216 blue:0.263 alpha:1]];
// Initialize your five tab controllers. with each tab has its own navigation controller
HomePageView *homePageView = [[HomePageView alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];
ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];
ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];
RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];
// initialize tabbarcontroller,set your viewcontrollers and change its color.
self.tabC = [[UITabBarController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
[self.tabC setViewControllers: controllers animated:NO];
[_window addSubview:self.tabC.view];
// Show window
[self.window makeKeyAndVisible];
return YES;
}
I'm guessing that you're setting the titles in the viewDidLoad or viewDidAppear methods of the controllers. That won't work, because, while all the controllers are instantiated in the app delegate, only the controller at index 0 has its view loaded, and thus viewDidLoad will not be run for the other controllers. Instead, you should set the titles on the navigation controllers in the app delegate,
ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
nav2.tabBarItem.title = #"Profile";

TabBarController status bar issue in iOS7

I added the UITabBarController view on the UIWindow. TabBarController view is messing up with Status Bar. The TabBarController is in the MainWindow.xib. How can i fix this?
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
tabController.viewControllers = [NSArray arrayWithObjects:nearbySplit, mySplit, allSplit, messageSplit, nil];
tabController.selectedIndex = 0;
window.rootViewController = tabController;
[window addSubview:tabController.view];
[window makeKeyAndVisible];
Add the this code in view controller
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone; // iOS 7 specific
in your viewDidLoad method.

Tab bar not appearing

The tab bar for this project isn`t showing up, instead it just shows a black screen.This tab bar is enter in pragmatically in application launch in app delegate.
main_tab=[[UITabBarController alloc]init];
viewcontroller = [[HomeViewController alloc]init];
viewcontroller.title =#"Home";
UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:viewcontroller];
viewcontroller1 = [[SearchViewController alloc]init];
viewcontroller1.title =#"Search";
UINavigationController *nav1 =[[UINavigationController alloc]initWithRootViewController:viewcontroller1];
tabs_array=[[NSArray alloc]initWithObjects:nav,nav1, nil];
main_tab.viewControllers=tabs_array;
[self.window addSubview:main_tab.view];
[self.window makeKeyAndVisible];
return YES;
Try replacing this line
[self.window addSubview:main_tab.view];
With this
self.window.rootViewController = main_tab;

Presenting Modal View Controller From Xib

I would like to show a modal dialog from a xib. The code that shows my window is:
self.vcSettings = [[ViewControllerSettings alloc] initWithNibName:#"ViewControllerSettings" bundle:[NSBundle mainBundle]];
[self presentModalViewController:self.vcSettings animated:YES];
When this runs though, I get a blank screen, and not what was inside of my ViewControllerSettings.xib. I imagine I'm showing the view incorrectly somehow. Any advice is appreciated.
EDIT:
I think this should be
[self.navigationController presentModalViewController:self.vcSettings animated:YES];
but for some reason self.navigationController is nil.
EDIT:
Self is a UIViewController instantiated in my AppDelegate like so:
UIViewController* viewMain = [[ViewController_iPhone alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = viewMain;
[self.window makeKeyAndVisible];
You need to create a UINavigationController, set it's root view to the XIB controller that you want to present (in your case vcSettings), then present the UINavigationController
self.vcSettings = [[ViewControllerSettings alloc] initWithNibName:#"ViewControllerSettings" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vcSettings];
[self.navigationController presentModalViewController:controller animated:YES];

How to change the color of UITabbarViewController's navigationBar?

There is a UITabBarController
- (void)getToMCGatherViewController
{
mCGatherViewController = [[MCGatherViewController alloc] initWithNibName:#"MCGatherViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mCGatherViewController];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
In the .h file:
#interface MCGatherViewController : UITabBarController
In the .m file . I want to change the color of the view's navigationBar
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor=[UIColor greenColor];
}
and it does not work at all.
Help me with this problem , thank you in advance!
just add
[navigationController.navigationBar setTintColor:[UIColor greenColor]];
after
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mCGatherViewController];
in your getToMCGatherViewController method.
Just edit your code like this and try I think this will work for you.
mCGatherViewController = [[MCGatherViewController alloc] initWithNibName:#"MCGatherViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mCGatherViewController];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.view addSubview:nav.view];
Then you change your Navigation Bar tint color.

Resources