3

所以我的应用程序的前提是它有多个选项卡,每个 tabViewController 都有一个 webView 属性,可以加载不同的网页。

我不确定到底出了什么问题,以及为什么会崩溃。

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6a7c5b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key webView.'

我构建应用程序的方式是为每个选项卡创建单独的 ViewController 类。我将 IBOutlets 包含到 WebView 中,并将它们链接到我包含在情节提要中的 webView。我还将 CustomClass 设置为 ViewController 类。

这是我的代码示例(它在 ViewControllers 中几乎是同义词):

AmericaViewController.h

#import <UIKit/UIKit.h>
@interface AmericaViewController : UIViewController
@property (nonatomic, weak) IBOutlet UIWebView *webView;
@end

AmericaViewController.m

#import "AmericaViewController.h"
@implementation AmericaViewController
@synthesize webView = _webView;

-(void)viewDidLoad
{
    [super viewDidLoad];

    // allow user to pinch-zoom page
    self.webView.scalesPageToFit = YES;
    self.webView.multipleTouchEnabled = YES;

    //load webView
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://baylornotes.org/articles/America"]]];   
}

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

@end
4

1 回答 1

0

根据例外情况,您的 UIViewController 之一没有属性 webView。也许你的一个类写得不好,或者你忘记在 xib 中设置正确的类......

于 2012-07-11T19:06:10.343 回答