我知道這是一個這樣簡單的問題,但我一直在努力,它不會工作。我試圖讓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