UINavigationBar is under StatusBar - objective-c

I'm developing a tiny app. And I'm having a problem I can't solve. I'm pushing a viewController to a navigationController and this screenshot is showing what's happening.
This is the code I'm using:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
TestViewController *testViewController =[[TestViewController alloc] init];
[navController pushViewController:testViewController animated:YES];
It's driving me crazy, I been gogling for an hour without success, any idea how to fix this?
Update
Is something related with the statusbar. If I change in the info.plist file the "Status Bar is initially hidden" to "NO", then the app works fine but the status bar is shown in the launch screen. Any Idea?

Try initializing your nav controller differently
TestViewController *testViewController =[[TestViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:testViewController];
[self.window setRootViewController:self.navController];
[self.window makeKeyAndVisible];
And for sake of all saints use capital letters for class names.

What I finally did is positioning the UINavigationBar manually. I hope it helps someone else!

Related

ios7 Tabbar covers tableview

I have a new ios7 tabbar app. the app delegate looks something like this.
SomeViewController *someView = [[SomeViewController alloc] initWithNibName:#"SomeViewController" bundle:nil];
UINavigationController *someNav = [[UINavigationController alloc] initWithRootViewController:someView];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:someNav, nil];
self.tabBarController.delegate = self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
SomeViewController is a simple view with a full size UITableView embedded. Now when the application runs the tableview will not scroll above the tab bar.
I have tried many many suggestions, such as
self.edgesForExtendedLayout = UIRectEdgeNone;
self.tabBarController.tabBar.translucent = NO;
but nothing seems to work. In IB I turn on the guides and set the height of the table view to be above the tab bar but that doesnt work either.
Rather stuck on something I am sure is very simple.
TIA
Does:
self.tabBarController.edgesForExtendedLayout = UIRectEdgeNone
help?

Second UIScreen causing problems with UIStoryboards

In my app delegate i set up another screen (for airPlay).
When i create a second window and assign the Second screen to it and run the app the TableView in my storyboard turns to a black colour. Its as if the tableView is not rendering correctly. I have isolated the problem to :
self.HDTVwindow.screen=[[UIScreen screens] objectAtIndex:1];
where the HDTVWindow is the second window for my airplay app. When i comment out this code the storyboard runs fine and my UITableView is nice and white. Am i confusing the storyboard by making two UIWindows in the appDelegate, even though they are assigned to different screens??
For my appDelegate see below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIScreen screens] count]>1)
{
CGRect frame = [[UIScreen screens]objectAtIndex:1].bounds;
self.HDTVwindow = [[UIWindow alloc] initWithFrame:frame];
UIImage* astonLogo=[UIImage imageNamed:#"AstonUni720p.png"];
UIImageView* astonLogoView=[[UIImageView alloc] initWithImage:astonLogo];
astonLogoView.frame=frame;
[self.HDTVwindow addSubview:astonLogoView];
self.HDTVwindow.hidden = NO;
self.HDTVwindow.screen=[[UIScreen screens] objectAtIndex:1];//PROBLEM!!
}
// Set Up Storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *mainViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
The problem disapears when ran with the iPad and an apple TV, it seems there might a bug in the simulator. In future i shall always run my code on real ios devices.

Navigation controller and no storyboards

I am writing an app in Objective C. For this project I cannot use ARC or storyboards. It should have 6 views. Firstly, the navigation controller shall keep table view (it will contain some data passed in from an array). In the toolbar on the top once the item has been pressed the app should move to second view.
I know that I need to code that in my delegate file, but I a not quite sure what needs to be included. Those were the requirements.
In fact when I run my app it does not show that navigation controller which got table view as my entry view. In the settings I cannot find a checkbox in order to select it and make it an entry view.
Any suggestions?
Best regards
Best way to use UITabBarController
Firsts Create all object of UIViewController and UINavigationController in AppDelegate.h file and use following method of AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds ]];
self.viewCon=[[ViewController alloc] init];
self.navCon=[[UINavigationController alloc] initWithRootViewController:self.viewCon];
self.navCon.navigationBar.tintColor=[UIColor blackColor];
self.viewCon.title=#"First View";
self.fView=[[FirstViewController alloc] init];
self.FnavCon=[[UINavigationController alloc] initWithRootViewController:self.fView];
self.FnavCon.navigationBar.tintColor=[UIColor blackColor];
self.fView.title=#"Secound View";
self.sView=[[SecoundViewController alloc] init];
self.SnavCon=[[UINavigationController alloc] initWithRootViewController:self.sView];
self.SnavCon.navigationBar.tintColor=[UIColor blackColor];
self.sView.title=#"Third View";
.
.
// create UIViewController and UINavigationController As you need
.
.
.
UIImage *img1=[UIImage imageNamed:#"Australia.gif"];
self.tbItem1=[[UITabBarItem alloc] initWithTitle:#"First Page" image:img1 tag:1];
self.viewCon.tabBarItem=self.tbItem1;
UIImage *img2=[UIImage imageNamed:#"Cameroon.gif"];
self.tbItem2=[[UITabBarItem alloc] initWithTitle:#"Secound Page" image:img2 tag:2];
self.fView.tabBarItem=self.tbItem2;
UIImage *img3=[UIImage imageNamed:#"Canada.png"];
self.tbItem3=[[UITabBarItem alloc] initWithTitle:#"Third Page" image:img3 tag:3];
self.sView.tabBarItem=self.tbItem3;
NSMutableArray *viewArr=[[NSMutableArray alloc] init];
[viewArr addObject:self.navCon];
[viewArr addObject:self.FnavCon];
[viewArr addObject:self.SnavCon];
self.tbCon=[[UITabBarController alloc] init];
self.tbCon.viewControllers=viewArr;
[self.window addSubview:tbCon.view];
[self.window makeKeyAndVisible];
return YES;
}

How to present a (no nib) ViewController

I've created a ViewController (without nib files), so how do I load this viewController in the app delegtate? my current code is:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
viewController = [[MyCustomViewController alloc] init...]; // I use a custom init method
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
And how can I use the presentModalViewController method to show new view controllers of the same "CustomViewController" class?
THANKS for the help!
NOTE: By the way, I do see that this code does call my initialization method, and my ViewDidLoad method in my customViewController is being called however the screen is still black....
It looks like your properties are not set up correctly.
Check this line:
viewController = [[MyCustomViewController alloc] init...]; // I use a custom init method
self.window.rootViewController = self.viewController;
check that self.viewController is okay, and there's nothing stopping you from just doing:
self.window.rootViewController = viewController;
Whoops, I was just missing this code in my viewDidLoad Method:
self.view.frame = CGRectMake(0, 0, 320, 480);
self.view.backgroundColor = [UIColor whiteColor];
So everything was working, but the screen by default is black and without a frame.
I had to do just that in one of the apps I'm working on. Try typecasting your view controller
CDViewController *viewController = (CDViewController*)self.window.rootViewController;
viewController.managedObjectContext = self.managedObjectContext;
viewController.managedObjectModel = self.managedObjectModel;
// Override point for customization after application launch.
return YES;

Root View Controller items are not clickable

After some great trouble, I was finally able to load my first Navigation / ViewController, only now none of the sub items are clickable. I mean, I have a two text fields, two buttons, and a switch, but none of them do anything when clicked. I know it is not a problem with my xib file, as these elements behave in the xib simulator for iPad.
This is all the code my application uses so far, and I don't see why it should not be clickable.
MainWindow.xib = empty nib file
int retVal = UIApplicationMain(argc, argv, nil,
#"iPadAppDelegate");
application: didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] init];
UIViewController *login = [[UIViewController alloc] initWithNibName:#"iPadLoginView" bundle:nil];
UINavigationController *nav_controller = [[UINavigationController alloc] initWithRootViewController:login];
self.window.rootViewController = nav_controller;
[self.window makeKeyAndVisible];
return YES;
replace your
self.window = [[UIWindow alloc] init];
with
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Replace
self.window.rootViewController = nav_controller;
with
[self.window addSubview:nav_controller.view];