I've been going through example after example trying to compare my project with others to see what I'm doing incorrectly however I have yet to find the answer. In short what I'm attempting to do for class is have a three button segmented control that will change the url that a UIWebView
displays.
However, when the app is ran it crashes on launch with the following console output
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:
The following is my code:
ViewController.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
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
//{
// IBOutlet UIWebView myWebView;
//}
//
@end
I'm only testing with the one site (ebay) until I can figure out exactly what I'm missing. Obviously I'm a student and am learning so please bear with me.
Thanks in advance.
I don't know if you already solve your problem...
The crash is maybe caused by Interface Builder which is linking your UIWebView to a property (IBOutlet) named appleWebView. I think that you renamed
appleWebView
tomyWebView
.To fixe this open the controller's xib (or storyboard), select the UIWebView, in the right panel open the connections inspector and remove the link to appleWebView.
Hope it helps!