简体   繁体   中英

pushViewController doesn't seem to work with storyboard and QLPreviewController

When trying to implement a dynamic table (using code) with a storyboard tableviewcontroller, the detail view fails to get pushed when the following code is executed.

[[self navigationController] pushViewController:previewController animated:YES];

No errors are thrown. No clues whatsoever are given, except that the selected table cell gets highlighted blue and stays that way. The issue is prevalent when using storyboards, but not when using xibs.

Here is the didSelectRowAtIndexPath method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    previewController.dataSource = self;
    previewController.delegate = self;

    // start previewing the document at the current section index
    previewController.currentPreviewItemIndex = indexPath.row;

    [[self navigationController] pushViewController:previewController animated:YES];
    [previewController release];
}

Here is a link to a sample project with the issue .

Your QLPreviewController isn't pushed because [self navigationController] is nil.

You have to add a UINavigationController to your storyboard like this:

(Assuming that FirstViewController is your UITableViewController) Left to right: UITabBarController, UINavigationController, FirstViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM