0

I have a UIViewController "PdfViewController" with a view containing an UIScrollView wich is containing an UIWebView, designed by storyboard. I'm using storyboard in Xcode 4.2 with ARC. If I start PdfViewController as initial ViewController the webview is shown as expected. I want the PdfViewController to show a PDF from a list of PDF's. So I made a NavigationController containing a TableViewController with the document titles. If I try to show the PdfViewController by "tableView didSelectRowAtIndexPath" the view stays black and doesn't load the selected document. There is no errer message from Xcode.

The viewDidLoad and the viewWillAppear from PdfViewController get called.

Here the initialisation of the PdfViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PdfViewController *pdfViewController = [[PdfViewController alloc]init];
    [pdfViewController setFileName:@"test"];
    [self.navigationController pushViewController:pdfViewController animated:YES]; 
}

-It seems, the problem is that the PdfViewController does not load the corrsponding nib by itself. If I make a seque from the TableViewCell, the PdfViewController is loaded correctly.

I changed the code to:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController.viewControllers.lastObject setFileName:@"test"];
}

The only thing to know here, is that the viewDidLoad und viewWillAppear are called before the execution of tableView didSelectRowAtIndexPath, so the PDF has to be loaded in viewDidAppear.

  • Nothing jumps out as obviously incorrect. Could you post the working code you used to see the the `PdfViewController` shows up correctly when it's the initial view? – gregheo Mar 02 '12 at 21:06

1 Answers1

1

With Xcode 4.2 or later, you can pass the data between two view controllers via segue.

Please Check:

How to pass prepareForSegue: an object

Your code may look like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
  if ([[segue identifier] isEqualToString:@"__YOUR_SEGUE_STRING__"]) {
     PdfViewController *pdfViewController = 
     (PdfViewController*)[segue destinationViewController];
    //
    // write your code here
    //
    [pdfViewController setFileName:@"test"];
  }
}
Community
  • 1
  • 1
naota
  • 4,695
  • 1
  • 18
  • 21