2013-05-30 23 views
0

我是非常新的Xcode,但我希望添加一些額外的功能,我的基本應用程序。此功能應在首次啓動時記錄一個字符串。出於調試目的,我也要求程序輸出一個字符串,即使它不是第一次啓動。我似乎無法在任何地方找到這些消息(我假設Xcode會像大多數IDE那樣捕捉到它們)。我是否在正確的文件中做這件事?該應用程序使用標籤欄控制器。Objective-C第一次啓動代碼被忽略

感謝

// 
// ViewController.m 
// 
// Created by Joel Kidd on 29/05/2013. 
// 
// 

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"]) { 
     NSLog(@"This is not the first launch."); 
    } else { 
     // Place first launch code here 
     NSLog(@"This is the first launch!"); 
     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 
    } 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

所有'NSLog'消息都應該出現在調試區域面板(視圖>調試區域>激活控制檯)中,並且應用程序委託的'application:didFinishLaunchingWithOptions:'應該是檢查首次啓動的理想位置。我希望這是有道理的... – Alladinian

+0

完美!將它放在應用程序委託中似乎可以解決它!非常感謝! (爲什麼不作爲答案提交?:D) – jskidd3

+0

完成。很高興這有助於你:) – Alladinian

回答

4

所有NSLog消息就會出現進入調試區域面板(查看>調試區>激活控制檯),也application:didFinishLaunchingWithOptions:您的應用程序代理的是檢查的第一發射的理想場所(在你的例子中,每當你的控制器的視圖被加載時,代碼就會被執行)。

+0

非常感謝! – jskidd3