iphoneipaduitableviewuiviewcontrolleruiwebview

Push UIWebView as detail view (table)


I want to create a app, where I'll have say 10 table rows (list view) and each would have a detail view. Now for each detail view, I want to show 10 different remote htmls (in UIWebView)?

How do I do this? Should I use array to store the 10 URLs? How do I pass the URL from list to detail view?

Just to add: I also want to show an iAd on the detail view. So hope that can be easily integrated.


Solution

  • You can create a WebViewController that will act as the "detail view". Add a new UIViewController subclass to your project and just add a UIWebView and an ADBannerView to your nib file. Make an outlet for your webView and you should be good to go. From your list view, you can create a new detailViewController and load your row-specific url to the webView:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSString* url = [[dataArray objectAtIndex:indexPath.row] objectForKey:@"url"];
        if (![url isEqualToString:@""]) {
            WebViewController* detailViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
            [self.navigationController pushViewController:detailViewController animated:YES];
            [detailViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
            [detailViewController release];
        }
    }
    

    This is a quick way to do that - you could create a custom -init method that accepts a url if you want. You should also use the methods of the UIWebViewDelegate in order to show some loading feedback/error message regarding the webView:

    @interface WebViewController : UIViewController <UIWebViewDelegate> {
        IBOutlet UIWebView* webView;
    }