【问题标题】:Collection view controller in split view does not update拆分视图中的集合视图控制器不更新
【发布时间】:2012-10-26 06:29:23
【问题描述】:

我使用主从应用程序模板创建了一个项目。该项目针对 iphone 和 iPad。

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

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

现在在情节提要中,iphone 版本在表格和集合(主/细节)控制器之间有一个 segue,一切正常。

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 版本的拆分视图中。在情节提要中,主视图和详细视图之间存在关系而不是分隔。当我选择表格行时执行的唯一代码是:

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");
    }
}

我可以看到我的自定义“入站”对象已正确传递给详细视图控制器。但是由于某种原因,collection view 没有更新。

有什么想法吗?

【问题讨论】:

    标签: ios xcode ipad uisplitviewcontroller uicollectionview


    【解决方案1】:

    在 iPhone 版本上,新视图被推送到屏幕上,因此您的方法之一是根据 detailItem 初始化视图。

    在 iPad 中,详细视图已经在屏幕上。您需要确保您的详细视图设置器函数将重新加载集合视图的数据 - 我敢打赌您目前没有这样做......

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

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

    提姆

    【讨论】:

    • “我敢打赌你现在不会那样做......” 你的赌注已经确定了!那成功了!非常非常感谢!
    • 蒂姆,如果你有空闲时间,请看看我的另一个问题 :)
    猜你喜欢
    • 2023-03-18
    • 2017-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    相关资源
    最近更新 更多