2012-12-01 17 views
2

做的NSLog我有這個安裝在我上課的時候意外的行爲:IOS - 試圖從didViewAppear

- (void)viewDidAppear:(BOOL)animated 
{ 
    NSLog(@"test"); 
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"get_business_ideas" ofType:@"html"]; 
    NSURL *url = [NSURL fileURLWithPath:htmlFile]; 
    NSURLRequest *rq = [NSURLRequest requestWithURL:url]; 
    [theWebView loadRequest:rq]; 
} 

的的NSLog聲明從來沒有出現在我的記錄屏幕,但其餘代碼似乎是因爲工作uiWebView會渲染。這怎麼可能?這是一個新項目,或許我必須設定一些措施以確保可以看到日誌記錄?

謝謝!

更新:這裏是整個文件:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    { 
     //load iphone image 
     UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"building"]]; 
     imgView.frame = self.view.bounds; // to set the frame to your view's size 
     [self.view addSubview:imgView]; 
     [self.view sendSubviewToBack:imgView]; 
    } 
    else 
    { 
     //load ipad image 
     UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"[email protected]"]]; 
     imgView.frame = self.view.bounds; // to set the frame to your view's size 
     [self.view addSubview:imgView]; 
     [self.view sendSubviewToBack:imgView]; 
    } 

    NSLog(@"2"); 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // 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 
+1

燦你在該方法中放置了一個斷點來查看它是否被命中?只需點擊想要代碼暫停的行上代碼左側的細條,如果它從不暫停,那麼該方法永遠不會被調用。 –

+0

這究竟在哪裏? – JoshRagem

+0

@Kris Gellci剛剛嘗試過。代碼確實到達那裏,但日誌永遠不會發生。也許我的日誌屏幕無法正常工作? – GeekedOut

回答

3

是否增加對你的超級呼叫解決這一問題?

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    NSLog(@"test"); 
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"get_business_ideas" ofType:@"html"]; 
    NSURL *url = [NSURL fileURLWithPath:htmlFile]; 
    NSURLRequest *rq = [NSURLRequest requestWithURL:url]; 
    [theWebView loadRequest:rq]; 
} 

(不管是什麼結束了在這裏修理你的問題...請務必保持的[超級]在調用這個方法......它的每API文檔需要)。

您提到您已顯示底部窗格,但未顯示任何調試消息。仔細檢查,點擊中間的顯示圖標,底部面板(而不是在Xcode中的右上角的外觀相似按鈕)上,控制檯部分正在顯示除了變量:

Console

+0

@J Shapiro只是試了一下,它沒有工作:(我有另一個項目,我只是使用NSLog沒有考慮它,它只是工作。不知道在這種情況下有什麼問題 – GeekedOut

+0

爲什麼會影響OP日誌? – JoshRagem

+0

@GeekedOut - 請參閱我的最新編輯。 –