我正在尝试使用通用webview详细制作主 - 详细视图,其中URL随主视图控制器中的按钮选择而变化。显然我是新手,我需要帮助!
在主视图mfile中的我通过这样的按钮发送:
-(IBAction)myButton1:(UIButton *) sender {
[self.detailVC location:@"http://google.com"];
}
-(IBAction)myButton2:(UIButton *) sender {
[self.detailVC location:@"http://yelp.com"];
}
详细视图mfile我有:
-(void)location(NSString *)myLocation{
_theLocation = myLocation;
}
-(void) viewDidLoad {
[super viewDidLoad];
NSURL *videoURL = [NSURL URLWithString:self.theLocation];
NSURLRequest *request = [NSURL Request requestWithURL:videoURL];
[self.webview loadRequest:request];
}
我没有收到构建错误,但没有加载任何URL。请帮忙!
答案 0 :(得分:2)
您应该知道- (void)viewDidLoad Called after the controller’s view is loaded into memory
,在您的问题中,似乎self.detailVC在内存中始终存在,不应该调用viewDidLoad
。
您可以直接在- (void)setLocation(NSString *)myLocation
更新网络视图:
- (void)setLocation(NSString *)myLocation
{
_location = myLocation;
NSURL *videoURL = [NSURL URLWithString:self.location];
NSURLRequest *request = [NSURL Request requestWithURL:videoURL];
[self.webview loadRequest:request];
}