I am moving from theory to some practice. I’ve downloaded from Apple site a couple of sample codes. The first app is TableViewSuite from
https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html
Looks nice and attractive. The most thing I like is mastering .nib file programmatically. I tried to repeat this app, but oh Dear, what kind of project to choose?
- Navigation-Based Application
- View-Based Application
or
- Window-Based Application?
First I tried Window-Based Application cos it promises
This template provides a starting point for any application. It provides just an application delegate and a window.
Sounds good. Just window and delegate, but when I started to write code I’ve faced such dilemma. In Apple’s code, the first thing I have to implement for exposing nib file with table view is
- (void)applicationDidFinishLaunching:(UIApplication *)application {
/*
Create and configure the navigation and view controllers.
*/
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
// Retrieve the array of known time zone names, then sort the array and pass it to the root view controller.
NSArray *timeZones = [NSTimeZone knownTimeZoneNames];
rootViewController.timeZoneNames = [timeZones sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;
[aNavigationController release];
[rootViewController release];
// Configure and display the window.
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
This method is clear for me. I mean it’s clear for me what it does. In my app this method is implemented in quite different way.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
It returns BOOL instead of returning void and doesn’t get (UIApplication *)application parameter and I can’t initialize RootViewController with style.
So, what kind of project should I choose? Please help me with your advice. Thanx in advance.
Hey nathan both these method does the same.
And if you are missing
applicationinstance then you can create it using[UIApplication sharedApplication]as this is a singleton and will return the same instance every time.If you are new to iPhone then go for View Based first then go for Navigation based app and then finally for window based application.
And about the two method above
- (void)applicationDidFinishLaunching:(UIApplication *)applicationmethod is used in earlier versions of iOS to initialize the application and prepare it to run. In iOS 3.0 and later, you should use the
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsinstead.These are the lines straight from apple’s docs you can check here
The difference between these two method is that when your applicaion is launched due to local/push notification the the method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsis called and a dictionary is passed as launch option. So use this one instead of other.And about the above downloaded code it is a navigation based application.