如果您的視圖控制器是AppDelegate中的一個屬性,相似的代碼參考
@interface AppDelegate_Shared : NSObject <UIApplicationDelegate, UIAlertViewDelegate, OMFDataLoadDelegate> {
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
UIWindow *window;
UITabBarController *tabBarController;
}
則可能得到由AppDelegate中被分配時分配。根據蘋果文檔viewDidLoad在視圖加載到內存後運行,這可能有點令人困惑,因爲語言可以讓你相信它是在它被加載到屏幕上的時候。
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW25
移動你的NSLog語句viewDidAppear爲您所期望的結果。這裏有兩個示例代碼片斷,您應該期望加載語句的方式。
ViewController.m
- (void) viewDidLoad {
NSLog(@"1st - this occurs when appDelegate allocates this object");
}
- (void) viewDidAppear {
NSLog(@"3rd - this should appear after the applicationDidFinishLaunchingStatement");
}
AppDelegate_Shared.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"2. Starting AppDelegate_Shared");
[window addSubview:self.tabBarController.view];
[window makeKeyAndVisible];
NSLog(@"4. Leaving AppDelegate_Shared");
return YES;
}
感謝特魯瓦什爲你提供了負擔..並且我申請了你所擁有的東西,但順序是1,2,4,3。我的問題是「什麼是代碼流?」我首先在文檔'main.m'中調用'appdelegate class',然後調用其他類來調用我們在applicationDidFinishLaunch方法中編寫的內容..可以解釋這個.. – chandra 2010-08-23 05:15:19