我的课堂上有以下设置:

- (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

最佳答案

添加 super call 能为您解决此问题吗?

- (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];
}

(无论是什么最终解决了您的问题,请确保在此方法中保留[super]调用...根据API文档,这是必需的)。

您提到您的底部窗格显示,但是没有调试消息显示。通过单击底部面板上的中间显示图标,仔细检查是否除了变量之外还显示了控制台部分(不是Xcode右上方的外观相似的按钮):

10-07 19:38
查看更多