ios - 尝试从didViewAppear执行NSLog时的意外行为

时间:2012-12-01 02:03:55

标签: ios nslog

我在班上有这个设置:

- (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:@"building@2x"]];
        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 :(得分: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