开发者

What kind of project type for TableViewSuite App

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?

  1. Navigation-Based Application
  2. View-Based Application

or

  1. 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 = [[UI开发者_Go百科NavigationController 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 application instance 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 *)application
method 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 *)launchOptions instead.
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 *)launchOptions is 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.


As far as what type of project to use, I think choosing a Window based application is a good starting point. As you said it's a window and a delegate and those are pretty much the essentials.

This method:

  • (void)applicationDidFinishLaunching:(UIApplication *)application

is actually used in older versions of iOS. You should be using:

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

This method basically does the same thing except it takes two parameters instead of 1. The first is the UIApplication (just like the first method). The 2nd parameter is a dictionary the tells you why the application was launched (opened from springboard, opened as a result of acting on a push notification, etc).

As for the return value, you probably want to return NO when just starting out. If your app is going to handle URL resources then you will probably want to re-implement it so that it looks inside the options dictionary to see if the app is launching because the user is trying to open a file or resource that your application claims to support (in which case you would return YES).

There should be no reason the code you posted above cannot be used. You just need to add a return value. There shouldn't be anything stopping you from initializing your UINavigationController or your RootViewController (which I assume is a subclass of UITableView).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜