問題描述
將案例編碼到 appDelegate 文件中 (The case(s) coding into appDelegate file)
I have a question regarding iOS development;iPhone/iPad. What is the case(s) I need to code inside AppDelegate.m/h file? Can I drag and drop properties to AppDelegate.h file (pointer arrows from view to header file)? For example, once you create non‑storyboard app via xibs when you store TableViewController inside NavigatioController you initialize those two inside AppDelegate.m file.
‑ (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewCon = [[UITableViewController alloc]init];
self.navCon = [[UINavigationController alloc]initWithRootViewController:self.viewCon];
return YES;
}
I just want to know why you do so. Why don't you do so in ViewController.m file instead? Anyway, this way works fine. And I want to know other similar cases (some of them probably) when you code in AppDelegate file. Best regards
‑‑‑‑‑
參考解法
方法 1:
No you cannot and should not drag and drop properties into the appDelegate. The main use of the AppDelegate is for saving tasks before the app will be killed or resuming some simple user components when the app is returning from an idle or inactive state.
Some external components like the old facebook sdk and google analytics are usually setup in the didFinishLaunching method as well. But I must reiterate: the app delegate is NOT where you set up UI properties as if you are in a standard view controller.
(by uml、Tommy Devoy)