IOS blank start screen - ios

I created a controller called Login with the xib file. I'm wanna make it the start screen. so in my app delegate,
H file:
UIWindow *login;
#property (nonatomic, retain) IBOutlet UIWindow *login;
M file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self.login makeKeyAndVisible];
return YES;
}
am I missing anything like linking to interface builder? am getting a blank screen

I think you need to create a UIViewController subclass together with your login nib file and then alloc and init this view controller so that you can then make the UIViewController's view the main view.
Even better would probably be the use of storyboard, where you can easily set the initial view controller all on your storyboard.
There is a good Tutorial about iOS Storyboards. I personally find the use of storyboards very convenient. In this SO question I listed some of the pros and cons of storyboards (IMHO):
Does storyboard eliminate the need for .nib

Related

Shared iAd on Tabbed Application

New to iOS development and I have a tabbed app with 4 tabs. I have an iAd showing on one tab and I don't want to regurgetate the code on every view controller and I know this is not the correct way to implement anyway. I have looked at the Apple code here and I'm struggling to be honest.
https://developer.apple.com/library/ios/samplecode/iAdSuite/Introduction/Intro.html
I have included the BannerViewController.m and BannerViewController.h in my application but I'm not fully sure how to get it to run the ad on each view controller.
Yours confused
JKX
Just grab a reference of UIWindow in any of your ViewController Class
Go to .m of your ViewController
#import "AppDelegate.h"
#interface ViewController ()
{
//make object of AppDelegate
AppDelegate *appDelegate;
}
Now in your viewDidLoad or ViewDidAppear grab the reference of window.
appDelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate.window addSubview:yourBannerView];

iOS self.window - when is it created?

when you start your app using single view template, and you add the NSLog(#"self.window = %#", self.window); in your first line of the AppDelegate.m's application: didFinishLaunchingWithOptions: method, you can see that self.window exists in your app.
However, when you start your app using empty template, and tried to log the self.window to the console, the result returns null. Even if you add storyboard and a view controller, and set its view controller as the initial view controller, and attempt to log the self.window, the result is the same - its value is set to null.
And note that whichever way you take, you can find you declare #property (strong, nonatomic) UIWindow *window; in AppDelegate.h by default. So I wonder why in the first case, you can see that self.window is initialized and set the value but not in the latter case. Also, if self.window is already declared and initialized in the first case but NOT in the second case, how can I find the initialization code?
It looks like in both cases, the #property declaration is same - and in both cases, as I mentioned, I tried to log the value of self.window in the FIRST LINE of the AppDelegate.m's application: didFinishLaunchingWithOptions: method.
So anything that I'm missing? I don't know why those two cases act differently despite me not finding any differences in both code and storyboard.
I use iOS 7 and Xcode 5. Thanks.
OK, when you create a project with a Storyboard or Nib then the project settings will tell the project that the storyboard/nib is the "Main Interface".
This triggers the application to load that interface on start up. This is why the self.window is created in these cases.
When you create an empty application there is no interface to set as the main interface.
You then need to create the window yourself like this...
-(void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *someController = [UIViewController... //create your initial controller
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
}
Something like this anyway. It's been a while.
Alternatively, if you create an empty application and then add a nib file that you want to use as the initial nib then you can select it in the project settings.
In the Target in General. In the section "Deployment Info" select the "Main Interface" from the nibs in your project. This will then load that nib when the application starts.
Xcode declares UIWindow as IBOutlet Object in Appdelegate and xcode itself hooks or connect it with the window of default ViewController.nib(Created by Xcode when you create non empty project).There is no need to initialise any object if you have declared it as Iboutlet and connected it with any UIController in nib.
Now in empty project if you want to create window declare it as outlet and connect it with window in exist in nib and make your AppDelegate as Files OWner.

UIViewController Is Not Working

This behavior is very odd. Every time I create a new project in Xcode 5.0.2 I cannot get it to work fully. Once the Single View Application template (or another) is created - everything seems OK: I have my delegate, storyboards and ViewController. They all run successfully and I can even see newly added UIView's in my Simulator.
Her is my generic code for ViewController:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
UIView *container;
}
#property (nonatomic,retain) IBOutlet UIView *container;
#end
#import "ViewController.h"
#interface ViewController (){}
#end
#implementation ViewController
#synthesize container;
- (void)viewDidLoad{
[super viewDidLoad];
NSLog(#"App loaded");
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
#end
But once I add properties to this controller class and synthesize them, the screen turns black during app running and no views or whatever was added before is ever seen anymore. Just a blank black color screen.
Where is the problem? Please note:
I checked Info*.plist and it points to Storyboard correctly
In delegate my didFinishLaunchingWithOptions returns YES
ViewController has a Initial View Controller checked and is the only one in the storyboard
viewDidLoad prints NSLog message successfully even though nothing is shown
What to check?
Here is a link to the project
A view controller is just that, a controller. The UIViewController's view property is what is visible on the screen (assuming you added it to the screen at some point, storyboard, programatic, xib, etc...)
Check the UIViewcontroller.view.superview. You should be able to get close to what you want.
The view controller properties thing is a complete red herring.
You're using a storyboard for your app, which has all of the relevant details in it. Then, in your app delegate, you've added a load of code to load in a new instance of the view controller and set it as your app's root view controller.
You don't need to do this if you have a storyboard. Just return YES from applicationDidFinishLaunching.. (which was originally the case, since you included the git history in the download!). The initial view controller from your storyboard will already be loaded up. What you've done is to basically ignore the storyboard.

iPhone app converted to iPad app shows iPhone xib not iPad xib

I am in the process of converting an iPhone app to a universal app.
I've changed all the xCode settings and added a new MainWindow-iPad.xib
I've hooked all the interface builder references up (e.g. MainWindow-iPad to the appropriate iPad class viewController, window etc)
I've added a new iPad class for the opening view controller and declared it in my AppDelegate.h file, and synthesized them in my AppDelegate.m file:
UIWindow *window;
UIWindow *windowiPad;
AppViewController *viewController;
AppViewControlleriPad *viewControlleriPad;
in the app delegate I check for which device I am running and load the appropriate class:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// Override point for customization after application launch.
navController = [[UINavigationController alloc] initWithRootViewController:viewControlleriPad];
// Add the view controller's view to the window and display.
[windowiPad addSubview:navController.view];
[windowiPad makeKeyAndVisible];
[navController setNavigationBarHidden:YES animated:NO];
} else {
//I am an iPhone!
// Override point for customization after application launch.
navController = [[UINavigationController alloc] initWithRootViewController:viewController];
// Add the view controller's view to the window and display.
[window addSubview:navController.view];
[window makeKeyAndVisible];
[navController setNavigationBarHidden:YES animated:NO];
}
And everything seems to work fine - except it still loads the iPhone nib/xib file AppViewController.xib instead of AppViewControlleriPad.xib. You're welcome to ask for more information but I can't figure out how to get it to load the AppViewControlleriPad.xib when running an iPad rather than the iPhone/original xib file.
I thought, perhaps naively, that if the xib file has the same name as the class of the view controller then the ViewController would use that as its xib.
How can I fix it so that the correct xib is loaded for the correct device?
You have a spelling mistake - correct sufix for iPad resources is "~ipad" instead of "-iPad". With "~ipad" your resources will be loaded automatically depending to device.
And you probably don't need another UIWindow for your iPad controllers. You can use the same window at app starting point. Good practice is also to have one view controller (inside you can perform some special things for different devices) and two nibs (one "normal" and the second one with "~ipad" sufix). In rare cases if whole controller behavior is completely different you may want to use two view controllers.
It may be due to the reason that you didn't connect iPad's view controller to files owner in IB.

How to add a UISplitViewController to a window-based app

If I create a new project in Xcode 3 - a "Universal" window based project, I can't seem to instantiate the UISplitViewController outlet I am adding to the iPad's XIB.
Starting with a brand new "window-based" project, I select "Universal" from the drop down (iPhone, iPad, Universal). I then create an IBOutlet property in AppDelegate_iPad.h, synthesize the variable in the .m file and release it in the appropriate dealloc.
I open MainWindow_iPad.xib file and add a UISplitViewController object to it. I then connect the "splitViewController" outlet from AppDelegate_iPad to the UISplitViewController I just dragged onto the XIB.
Unfortunately, when I run this, splitViewController is never instantiated. Consequently, I can't add it to the window's view or set it as the window's root controller. I check this by putting a break point in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
to view the splitViewController ivar - but unfortunately, it is always 0x0. Is there some special step I am missing? I've compared my code to the split view controller template in Xcode and I can't see any differences.

Resources