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];
[[currVie开发者_如何转开发w 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!
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
精彩评论