0

我正在尝试使用通用 web 视图详细制作主从视图,其中 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。请帮忙!

4

1 回答 1

2

您应该知道- (void)viewDidLoad Called after the controller’s view is loaded into memory,在您的问题中,似乎 self.detailVC 始终存在于内存中,不应该调用viewDidLoad.

您可以直接更新 web 视图- (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];
}
于 2013-05-07T23:07:39.813 回答