In UISplitViewController, can't make showDetailViewController:sender: push onto detail navigationController

前端 未结 3 687
不思量自难忘°
不思量自难忘° 2021-02-07 03:28

In iOS 8, view controllers can now call showDetailViewController:sender: to have the system determine the proper view controller to present the detail view controll

相关标签:
3条回答
  • 2021-02-07 03:56
    if (self.splitViewController.collapsed)
        [self.splitViewController showDetailViewController:self.itemVC sender:self];
    else
        self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
    
    0 讨论(0)
  • 2021-02-07 04:09

    The way You doing it have a problem. If your rotate the device(change the mode from collapsed to allVisible) after you select, you will find the detail vc without a navigation controller.

    If you call showDetailViewController:sender: in all cases and pass the view controller with a navigation controller it will work fine in both cases and also will fix the rotaion problem mentioned above.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        self.itemVC.item = self.itemStore.items[indexPath.row];
    
        UIViewController *vcToShow= [[UINavigationController alloc] initWithRootViewController:self.itemVC];
        [self showDetailViewController:vcToShow sender:self];
    }
    
    0 讨论(0)
  • 2021-02-07 04:13

    In showDetailViewController:sender: depending on the collapse property you need to create the controller you want to show in the detail.

    E.g. On the iPad in landscape mode it would already create the detail view controller from the storyboard but on the iPhone 5 where it is collapsed the view controller does not exist yet.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UINavigationController *detail;
        ImageViewController *imageVC;
    
       // on the iPhone (compact) the split view controller is collapsed
       // therefore we need to create the navigation controller and its image view controllerfirst
       if (self.splitViewController.collapsed) {
           detail = [[UINavigationController alloc] init];
           imageVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
           [detail setViewControllers:@[imageVC] animated: NO];
       }
       // if the split view controller shows the detail view already there is no need to create the controllers
       else {
           id vc = self.splitViewController.viewControllers[1];
           if ([vc isKindOfClass:[UINavigationController class]]) {
               detail = (UINavigationController *)vc;
               imageVC = [detail.viewControllers firstObject];
           }
        }
    
        [self prepareImageViewController:imageVC forPhoto:self.photos[indexPath.row]];
        // ask the split view controller to show the detail view
        // the controller knows on iPhone and iPad how to show the detail
        [self.splitViewController showDetailViewController:detail sender:self];
    }
    

    I hope this solves your issue.

    0 讨论(0)
提交回复
热议问题