0

我一直在通过示例尝试将我的项目与其他人进行比较,以查看我做错了什么,但是我还没有找到答案。简而言之,我试图为课堂做的是有一个三按钮分段控件,它将更改UIWebView显示的 url。

但是,当应用程序运行时,它会在启动时崩溃,并显示以下控制台输出

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7f969ab2dd80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key appleWebView.'
*** First throw call stack:

以下是我的代码:

视图控制器.M

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *theScroller;
@property (weak, nonatomic) IBOutlet UISegmentedControl *appleSite1;
@property (weak, nonatomic) IBOutlet UIWebView *myWebView;

@end

@implementation ViewController

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

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.theScroller.contentSize = CGSizeMake(280, 1000.0);
}

- (IBAction)appleSite1:(UIButton *)sender
{
    NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.google.com"]];

    [self.myWebView loadRequest:[NSURLRequest requestWithURL:url]];
}


@end

视图控制器.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
//{
//    IBOutlet UIWebView myWebView;
//}
//

@end

我只在一个站点(ebay)上进行测试,直到我能弄清楚我到底错过了什么。显然我是一名学生并且正在学习,所以请多多包涵。

提前致谢。

4

1 回答 1

0

我不知道你是否已经解决了你的问题......

崩溃可能是由将您的 UIWebView 链接到名为 appleWebView 的属性 (IBOutlet) 的 Interface Builder 引起的。我认为您已重命名appleWebViewmyWebView.

要解决此问题,请打开控制器的 xib(或故事板),选择 UIWebView,在右侧面板中打开连接检查器并删除指向 appleWebView 的链接。

希望能帮助到你!

于 2014-12-13T16:23:13.280 回答