2

I'm trying to display a UIViewController which displays a pdf file (PDFReaderViewController). I have a tabBarController with 4 tabs. I want to select the 4th tab, which is a UITableView with a list of files, and display the pdf with a navigation bar at the top. When the user is done viewing the pdf he can navigate back to the UITableView (4th tab). I'm able to display the 4th tab view but I can't get it to display the pdf. Here is my code:

    PDFReaderViewController *pdfController = [[PDFReaderViewController alloc] init];
    [pdfController initwithName:fileName];

    //display the right tab view
    UIViewController *currView = [tabBarController.viewControllers objectAtIndex:3];    
    [tabBarController setSelectedViewController:currView];
    [window insertSubview:tabBarController.view atIndex:0];

    [[currView navigationController] pushViewController:pdfController animated:YES];///this is not showing!!!!
    [currView loadView];

    [pdfController release];
    [window makeKeyAndVisible]; 

What am I doing wrong here? Thanks for your help!

dynamo42
  • 43
  • 7

1 Answers1

1

My best guess is that currView is not a navigation controller.

You need to make the 4th tab be a navigation controller, whose root view controller is the tableView. I'm guessing [currView navigationController] is returning nil.

The best way to see this is to set a breakpoint at the relevant line, then open the debugger and type po currView

Andrew Pouliot
  • 5,423
  • 1
  • 30
  • 34
  • You are correct...It is returning nil. The currView is a UIViewController I don't want to change it to be a UITableView since I will have to change all my code. What else can I do here? Thanks! – dynamo42 Mar 25 '11 at 15:47
  • You don't need to make it a UITableViewController, just embed it in a UINavigationController so you can push other view controllers. – Andrew Pouliot Apr 05 '11 at 19:21
  • Please, can you explain this a bit better? Maybe with example code even? – C0D3 Sep 26 '12 at 21:46