2012-10-05 44 views
0

我有一个UIViewController内,其中我把一个UIWebView的iOS - UIWebView中不显示HTML

然后我说这.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文件不在视图内渲染,而且我在这一行上得到警告:theWebView.delegate = self;它说:

从不兼容的类型BuildBusinessController * const_string分配给ID“UIWebViewDelegate

会有人知道我做错了什么?我感觉我差点忘了一些一件小事:)

回答

1

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

[self.view addSubview:theWebView]; 

更新:这个问题是由OP未能在故事板的UIWebView的配置委托造成的。这里提供的代码片段只有在您手动编码时才有效。否则,如@ F.X所述。在下面的评论中,Storyboard会自动实现这一点。

+0

对不起,那一行应该在哪里?我不会注意到loadRequest - 你的意思是viewDidAppear中的最后一行 - 那是行不通的。 – GeekedOut

+0

只需检查一下,您是否使用故事板创建了网页视图? – Alan

+0

是的,我使用故事板创建了视图,但是我手动编写了代码,这可能是问题所在。 – GeekedOut

1

你只是在你的类定义遗忘UIWebViewDelegate

#import <UIKit/UIKit.h> 

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

@end 
+0

谢谢!!! :)好赶上 - 让我出汗半个小时! – GeekedOut

+0

尽管我只是试过它,它仍然没有完全工作:(虽然它确实摆脱了错误 – GeekedOut

+0

问题可能是我在我的html文件build_business中使用下划线? – GeekedOut