0

I have an app. In this on the click of an Upload button a UITableView appears inside a UIPopOverController with a few entries. On clicking on any of these entries, a corresponding site should open in the wUIWebView of my UIDetailView of SplitView app.

I am using the following lines of code ::

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
hUrl = [kk objectAtIndex:indexPath.row];
hUrl = [Url stringByReplacingOccurrencesOfString:@" " withString:@"_"];

NSString *hisPage= [[NSUserDefaults standardUserDefaults] stringForKey:@"url_preference"];

Page = [hisPage stringByAppendingString:@"/index.php/"];

Page = [hisPage stringByAppendingString:hUrl];

NSURL *Url = [NSURL URLWithString:Page];
NSLog(@"%@", Url);
NSURLRequest *request = [NSURLRequest requestWithURL:Url];


self.detailViewController.webView.scalesPageToFit = YES;

[self.detailViewController.webView loadRequest:request];

}

The UITableView appears inside a UIPopoverController. However, I am unable to load the corresponding webPage. Can someone help me to sort this out ?? Thanks and regards.

kamalbhai
  • 510
  • 2
  • 10
  • 23
  • Have you checked if it logs the `URL`properly ? Do an `NSLog(@"Url: %@ ..Request: %@ ... WebView: %p",Url, request,self.detailViewController.webView);`, check if it's the values you need. – iNoob Jun 27 '12 at 10:47
  • I didn't see you push the detailViewController on the display stack? – user523234 Jun 27 '12 at 10:57
  • @iNoob .. I get the following ouput at the gdb on `NSLog` :: `Url: http://xxxx.com/index.php/ ..Request: ... WebView: 0x0 2012-06-27 16:27:41.671` – kamalbhai Jun 27 '12 at 11:01
  • @user523234 .. I think I haven't done that. But, I am unable to sort out as to where I should have pushed it. – kamalbhai Jun 27 '12 at 11:02
  • @kamalbhai Your Webview shows as `0x0` which means it hasn't been allocated. Are you sure you have `alloc init` your webview ? Make sure you have attached it properly in IB if you haven't created it programatically. – iNoob Jun 27 '12 at 11:03
  • yaaa .. I think this might be the problem. But, however, I have used the following line of code :: `detailViewController2.detailViewController = self.detailViewController;` in the file of `splitViewMasterViewController.m`. I suppose this allocates memory to webView. – kamalbhai Jun 27 '12 at 11:08
  • else .. how should I `alloc init` my `webView` and where ? – kamalbhai Jun 27 '12 at 11:10
  • @kamalbhai, You can `alloc init` your webview just below `NSURLRequest *request = [NSURLRequest requestWithURL:Url];`, something like `UIWebView*theWebView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];[theWebView loadRequest:request];[self.view addSubview:theWebView];`, if this is unreadable let me know – iNoob Jun 27 '12 at 11:27
  • @kamalbhai, and i hope you want the webview in same class where you have the popOverController. If the table's `didSelect` is in different class, then you've to follow delegate method protocol. It'll take a little while to learn. – iNoob Jun 27 '12 at 11:30

1 Answers1

0

Per your answer to my comment, the proper procedure to follow in this scenario is as follow:

  1. Implement a delegate method protocol for your popOverController instant.
  2. In didSelectRowAtIndexPath, call the delegate method back to the parent view controller (where your Upload button located). And passing back the Url string as a parameter.
  3. From the parent view controller, dismiss the popover and using the passed back Url to prepare your detailViewController and then push it onto display stack.

An example of delegate method can be found in this SO .

Community
  • 1
  • 1
user523234
  • 14,323
  • 10
  • 62
  • 102