我有一个UITableView,可以将内容加载到UIWebView中,如下所示:
//MainViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect bounds = [ [ UIScreen mainScreen ] applicationFrame ];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:bounds];
UIWebView *htmlView = [ [ UIWebView alloc ] initWithFrame:[scrollView bounds]];
htmlView.frame = CGRectMake(10,10,280,360);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[htmlView loadRequest:requestObj];
scrollView.contentSize = [htmlView bounds].size;
[scrollView addSubview:htmlView];
[detailsViewController.view addSubview:htmlView];
[htmlView release];
htmlView = nil;
[scrollView release];
scrollView = nil;
[[self navigationController] pushViewController:detailsViewController animated:YES];
[detailsViewController release];
}
所有提供给UIWebView的远程内容都来自我编写的Web服务。第一个屏幕截图是从标题为“词汇表”
的列表视图中选择单词时显示的内容
这一切都很棒,直到您关注链接,在这种情况下单击UIWebView内容中的“框架”链接。新内容已加载,但我需要告诉导航栏UIWebView已更改,因此我至少可以更改白色标题文本以匹配新内容。我应该实现哪些UIWebView方法以及它们应该去哪里?
答案 0 :(得分:3)
将视图控制器设置为UIWebView的委托,然后实现
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType