0

所以通常加载一个 UIWebView 我做..

   NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];
   [_webView loadRequest:request];

但是,现在我需要根据用户单击的表格单元格动态地执行此操作。我从 JSON 加载表格单元格,一切正常。现在我需要在单元格中获取帖子的“id”,并动态加载它。目前我已经尝试过了,但它不起作用......

NSURL *url = [NSURL URLWithString:@"http://www.google.com/story.php?id="];
url = [NSURL URLWithString:storyId relativeToURL:url];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

有小费吗?

4

1 回答 1

0

为什么不直接格式化 URL 字符串?

NSURL *url = [NSURL URLWithString:[NSString 
            stringWithFormat:@"http://www.google.com/story.php?id=%@", storyId]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
于 2013-02-28T16:01:41.013 回答