【发布时间】:2023-03-03 15:58:01
【问题描述】:
我知道这是一个如此简单的问题,但我一直在努力解决它,它就是行不通。我试图让 UITableView 在选择特定行时打开 URL。使用 NSLog 我可以看到 urlSelected 变量设置正确并正确传递给 UrlViewController,但它根本没有显示 webview。它仅显示带有黑屏的导航菜单。如果我在两个视图控制器之间添加推送关系,则 ViewController 会正确加载,但将 urlSelected 变量传递给 UrlViewController 时遇到问题。传递此变量的正确方法是什么,或者我是否需要在两个 ViewController 之间设置不同的关系?这是我目前拥有的:
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
非常感谢任何帮助。
【问题讨论】:
-
我已经回答了这个here!同样的问题很安静。
标签: xcode ios5 uiwebview tableview