拆分视图中的集合视图控制器不会更新

时间:2012-10-26 06:29:24

标签: ios xcode ipad uisplitviewcontroller uicollectionview

我使用主详细信息应用程序模板创建了一个项目。该项目针对iPhone和iPad。

我的主视图包含一个从数据库数据填充的表视图控制器。到目前为止没问题。

在详细视图中,我使用Collection视图控制器替换了默认视图控制器。我希望主表视图中的每一行都在集合视图中创建多个单元格。

现在在故事板中,iphone版本在表格和表格之间有一个区别。集合(主/细节)控制器,一切正常。

MasterViewController.m    
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        Inbound *current = inbounds[indexPath.row];
        [[segue destinationViewController] setDetailItem:current];
    }
}

我的自定义对象“入站”正在从主视图传递到详细视图。发生这种情况时,详细信息/集合视图控制器会更新单元格。

DetailViewController.m
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   //Go round the DB and update the cells
}

我的问题出在iPad版的拆分视图中。在故事板中,主视图和详细视图之间存在关系而不是segue。选择表行时执行的唯一代码是:

MasterViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        Inbound *current = inbounds[indexPath.row];
        self.detailCollectionViewController.detailItem = current;

        NSLog(@"%@",@"table cell clicked");
    }
}

我可以看到我的自定义“入站”对象正在传递给详细视图控制器。但由于某种原因,集合视图不会更新。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在iPhone版本上,新视图被推送到屏幕上,因此您的一种方法将基于detailItem初始化视图。

在iPad中,详细视图已经在屏幕上。你需要确保你的详细视图的setter函数会重新加载集合视图的数据 - 我敢打赌你现在没有这样做......

换句话说,你需要这样的东西(假设是ARC)

- (void)setDetailItem:(Inbound *)detailItem
{
    _detailItem = detailItem;
    [_collectionView reloadData];
}