我有一个使用 UITableViewController 的应用程序,它调用内部带有 UIWebView 的 UIViewController。我的一切工作正常,除了当我单击表格单元格时,它会将我带到 UIViewController 并在里面打开相应的 weburl,但是当我返回 UITableViewController 时它不会关闭网站。它抵消了网站,所以我知道我回到了 tableview 但网站仍然可见。我错过了什么?
WebViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated {
webView2.delegate = self;
webView2.backgroundColor = [UIColor clearColor];
NSString *urlAddress = self.magURL;
webURL = [NSURL URLWithString:urlAddress];
requestObj = [NSURLRequest requestWithURL:webURL];
[webView2 loadRequest:requestObj];
}
-(void)viewDidDisappear:(BOOL)animated
{
webView2.delegate = nil;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
TableViewController.m - (void)viewDidLoad { [super viewDidLoad];
magazineArray = [[NSMutableArray alloc] init];
[magazineArray addObject:@"Joyce Meyer"];
[magazineArray addObject:@"Perry Stone"];
[magazineArray addObject:@"Robb Thompson"];
[magazineArray addObject:@"R.W. Schambach"];
[magazineArray addObject:@"T.D. Jakes"];
[magazineArray addObject:@"Reinhard Bonnke"];
[magazineArray addObject:@"Pilot"];
self.navigationItem.title = @"Magazines";
magazineURL = [[NSMutableArray alloc] init];
[magazineURL addObject:@"http://mysolutionsmagazine.com/solutions/2013/magazine"];
[magazineURL addObject:@"http://google.com"];
[magazineURL addObject:@"http://smithmediagroup.com"];
[magazineURL addObject:@"http://smgvoices.com"];
[magazineURL addObject:@"http://facebook.com/smithmediagroup"];
[magazineURL addObject:@"http://twitter.com/smgvoices"];
[magazineURL addObject:@"http://youtube.com/smgvoices"];
MagazineURLViewController *urlController = [[MagazineURLViewController alloc] init];
urlController.urlHolder = newURLHolder;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
newURLHolder = [magazineURL objectAtIndex:indexPath.row];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(50, 100, 690, 750)];
NSURL *webURL2 = [NSURL URLWithString:newURLHolder];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:webURL2];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"Cell2"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
newURLHolder = magazineURL[indexPath.row];
[[segue destinationViewController]setMagURL:newURLHolder];
}
}