Root View Controller items are not clickable - objective-c

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];

Related

Orientation issue in ios8 when setting RootViewController

I'm working on an application in which i'm setting the rootViewController as,
if(token){
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:#"Home"];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[navigationController setNavigationBarHidden:YES animated:NO];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window setRootViewController:navigationController];
}
when this piece of code works the orientation is not working properly, the status bar rotates but the view stays the same.
This works perfectly in iOS7.1 and below but when it runs on iOS8.1 we get this issue.

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;
}

UINavigationBar is under StatusBar

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!

How to deal with storyboard instead of xib file in such case?

I have an example where I have animation when the app starts. At the start an image is displayed, then moves from right to left, then disappears. Below is the code I have.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewwController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewwController;
[self.window makeKeyAndVisible];
//add the image to the forefront...
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[splashImage setImage: [UIImage imageNamed:#"Default"]];
[self.window addSubview:splashImage];
[self.window bringSubviewToFront:splashImage];
//set an anchor point on the image view so it opens from the left
splashImage.layer.anchorPoint = CGPointMake(0, 0.5);
//reset the image view frame
splashImage.frame = CGRectMake(0, 0, 320, 480);
//animate the open
[UIView animateWithDuration:1.0
delay:0.6
options:(UIViewAnimationCurveEaseOut)
animations:^{
splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0);
} completion:^(BOOL finished){
//remove that imageview from the view
[splashImage removeFromSuperview];
}];
return YES;
}
What I want is to do this using a storyboard, so I changed the code as below.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MyBookViewController *myNew = [[MyBookViewController alloc] init];
self.myBookViewController = myNew;
self.window.rootViewController = self.myBookViewController;
[self.window makeKeyAndVisible];
However I don't see my viewcontroller (MyBookViewController). I only see the image moving from right to left, then a black screen.
Any idea what is going wrong?
I just did it myself with help of this SO question.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle: nil];
MyBook001ViewController *controller = (MyBook001ViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"firstStory"];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
i think it is because of you are allocating new MyBookViewController. instead it you have to give reference of storyboard, on which you have your UI design for MyBookViewController, like this
MyBookViewController *myNew=[self.storyboard instantiateViewControllerWithIdentifier:#"MyBookViewController"];
be sure for ViewController identifier
UPdate1:
try with
MyBookViewController *myNew=[self.window.rootViewController];

adding a uinavbaritem across all views

I have a uitabbarcontroller with uinavigation controller for 2 view controllers. i am trying to have a uinavigationitem (something like "settings" that exist in most of the apps). I am wondering if I need to define this item in every view (tabOneViewController, tabTwoViewController, etc.), or is there a global way to define this buttons so it will stay when I move between different tabs?
here is how I create my tab/nav controllers in my AppDelegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstTab alloc] initWithNibName:#"FirstTab" bundle:NSBundle.mainBundle];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondTab alloc] initWithNibName:#"SecondTab" bundle:NSBundle.mainBundle];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];