joshuahornby10
joshuahornby10

Reputation: 4302

Loading UIView from UITableViewController

I am trying to call a UIView inside of a UITableViewController.

JHWebViewController has been created in the storybaord.

JHWebViewController *myWebView = [[JHWebViewController alloc] init];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
myWebView.request = requestObj;

[self presentViewController:myWebView animated:YES completion:nil];

The error I get is Property 'request' not found on object of type 'JHWebViewController *'

Upvotes: 0

Views: 56

Answers (3)

MrBr
MrBr

Reputation: 1916

Maybe try to embed the web view in a modal view controller and present the controller modally. Declare a public NSURLRequest property and set it from the table view delegate method.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath` 
{
   YourEmbeddingViewController *evc = [[YourEmbeddingViewController alloc] init]; // subclass of UIViewController

   NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
   evc.request = requestObj;

   [self presentViewController:evc animated:YES completion:nil];
} 

Upvotes: 0

Mahboob Nur
Mahboob Nur

Reputation: 787

You can write the relevant code in UITableView didSelectRowAtIndexPath method I hope it will work for you

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath` 
{
   [self.view addSubview:myWebView.view]; 
} 

Upvotes: 1

nyanev
nyanev

Reputation: 11519

You try try this:

JHWebViewController *myWebView = [[JHWebViewController alloc] init];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
myWebView.scalesPageToFit = YES;

[self.view addSubview:myWebView.view];

Upvotes: 0

Related Questions