我知道这是一个这样简单的问题,但我一直在努力,它不会工作。我试图让UITableView在选择特定行时打开URL。使用NSLog我能够看到urlSelected变量被正确设置并正确传递给UrlViewController,但它不会显示webview。它只显示黑屏的导航菜单。如果我在两个视图控制器之间添加推送关系,那么ViewController会正确加载,但它无法将urlSelected变量传递给UrlViewController。传递这个变量的正确方法是什么,或者我需要在两个ViewController之间建立不同的关系?以下是我目前有:UIWebView无法加载
RootViewController.m:
#import "RootViewController.h"
#import "UrlViewController.h"
..........
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UrlViewController *webController = [[UrlViewController alloc] init];
if(indexPath.row == 0){
webController.urlAddress = @"http://www.yahoo.com";
NSLog(@"urlAddress being passed is:%@", webController.urlAddress);
[self.navigationController pushViewController:webController animated:YES];
}else if(indexPath.row == 1){
webController.urlAddress = @"http://www.google.com";
NSLog(@"urlAddress being passed is:%@", webController.urlAddress);
[self.navigationController pushViewController:webController animated:YES];
}else{
webController.urlAddress = @"http://www.abc.com";
NSLog(@"urlAddress being passed is:%@", webController.urlAddress);
[self.navigationController pushViewController:webController animated:YES];
}
}
UrlViewController.h:
@interface UrlViewController : UIViewController{
NSString *urlAddress;
}
@property (strong) IBOutlet UIWebView *webView;
@property (nonatomic, retain) NSString *urlAddress;
UrlViewController.m:
@implementation UrlViewController
@synthesize webView;
@synthesize urlAddress;
...........
- (void)viewWillAppear:(BOOL)animated {
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
NSLog(@"The value being receieved is:%@", urlAddress);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
我收到下面的输出NSLogs:
2012-03-28 09:53:30.266 BeloitTurner[4278:f803] urlAddress being passed is:http://www.yahoo.com
2012-03-28 09:53:30.269 BeloitTurner[4278:f803] The value being receieved is:http://www.yahoo.com
任何帮助,非常感谢。
我已经回答了这个[这里](http://stackoverflow.com/questions/8791517/pass-a-uiwebview-request-using-prepareforsegue/13723765#13723765)!这是一个安静的问题。 – Ashoor 2012-12-05 13:11:32