iPad - DetailViewController以编程方式

时间:2015-01-14 22:52:32

标签: ios ipad uisplitviewcontroller

我正在使用UISplitViewController的iPad应用程序。我还使用DetailViewController来显示XML中的一些信息,但信息不会显示在DetailViewController中,而是显示在MaterViewController中。我真的不知道如何解决它。你能帮忙吗?谢谢

有代码:

-(void) showDetailsForIndexPath:(NSIndexPath*)indexPath
{
    [self.searchBar resignFirstResponder];
    DetailViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];

    Slova* slova;

    if(isFiltered)
    {
        slova = [filteredTableData objectAtIndex:indexPath.row];
    }
    else
    {
        slova = [self.slovoArray objectAtIndex:indexPath.row];
    }

    vc.slovoItem = slova;
    [self.navigationController pushViewController:vc animated:true];
}

1 个答案:

答案 0 :(得分:1)

原因是您正在将新UIViewController推送到self的堆栈,这可能是MasterViewController。相反,使用Apple的Master-Detail Application创建一个新项目,您将看到他们是如何做到的。

警告: 他们使用Storyboard,但很有可能在代码中完成所有操作。

在Apple的示例中,MasterViewControllerDetailViewController从一开始就是可见的(横向)。

了解Apple的示例如何为detailItem设置slovoItemDetailViewController?):

#pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSDate *object = self.objects[indexPath.row];
        DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
        [controller setDetailItem:object];
        controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
        controller.navigationItem.leftItemsSupplementBackButton = YES;
    }
}

因此,您已经看到DetailViewController,并且您只需更新其detailItem属性。

因此,DetailViewController中存在以下代码:

#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem {
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}
- (void)configureView {
    // Update the user interface for the detail item.
    if (self.detailItem) {
        self.detailDescriptionLabel.text = [self.detailItem description];
    }
}