html - iOS - UIWebView 不显示 HTML

标签 html ios ios5 uiviewcontroller uiwebview

我有一个 UIViewController,我在里面放了一个 UIWebView

然后我将其添加到 .h 文件中:

#import <UIKit/UIKit.h>

@interface BuildBusinessController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *theWebView;

@end

并将其作为 .m 文件

#import "BuildBusinessController.h"

@interface BuildBusinessController ()

@end

@implementation BuildBusinessController
@synthesize theWebView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    theWebView.delegate = self;
}

- (void)viewDidUnload
{
    [self setTheWebView:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


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

@end

但是 build_business.html 文件没有在 View 中呈现,而且我在这一行收到警告:theWebView.delegate = self;其中说:

从不兼容的类型 BuildBusinessController *const_string 分配给 id 'UIWebViewDelegate

有人知道我在这里做错了什么吗?感觉我忘记了一些小事 :)

最佳答案

除了 F.X.回答,我想你忘了在 viewDidAppear 中添加这个(在 loadRequest 之后):

[self.view addSubview:theWebView];

更新:该问题是由于 OP 未能在 Storyboard 中为 UIWebView 配置委托(delegate)引起的。此处提供的代码片段仅在您手动编码时才有效。否则,如@F.X 所述。在下面的评论中,Storyboard 将自动实现这一点。

关于html - iOS - UIWebView 不显示 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12752068/

相关文章:

html - div中的CSS标记位置

javascript - AngularJs POST 方法到 springboot api

objective-c - 在某些情况下将 NSString 转换为 NSDate 会增加一年

javascript - 如何使用javascript测试元素在列表中排序?

ios - 在 iOS 中通过 AVAssetReaderTrackOutput 获取样本缓冲区时音频丢失?

ios - UrbanAirpush 编译错误,缺少一些文件

javascript - gayadesign 如何将图像放入 QueryLoader 中

html - TTY 电话号码是否应该作为普通号码进行超链接?

X代码/iOS5 : Show UIDatePicker when UITextField is pressed (+ hide default keyboard)

iphone - 自定义标签栏 iOS - 3 个按钮