簡體   English   中英

拆分視圖中的集合視圖控制器不會更新

[英]Collection view controller in split view does not update

我使用主詳細信息應用程序模板創建了一個項目。 該項目針對iPhone和iPad。

我的主視圖包含一個從數據庫數據填充的表視圖控制器。 到目前為止沒有問題。

在詳細視圖中,我將默認視圖控制器替換為“集合”視圖控制器。 我想為主表視圖中的每一行在集合視圖中創建許多單元格。

現在在情節提要中,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版本的Split視圖中。 在情節提要中,母版視圖和詳細信息視圖之間沒有關系,而無關系。 選擇表行時執行的唯一代碼是:

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

我可以看到我的自定義“入站”對象已正確傳遞到詳細信息視圖控制器。 但是由於某些原因,集合視圖不會更新。

有任何想法嗎?

在iPhone版本上,新視圖被推到屏幕上,因此您的方法之一將是基於detailItem初始化視圖。

在iPad中,詳細信息視圖已顯示在屏幕上。 您需要確保詳細信息視圖的setter函數將重新加載集合視圖的數據-我敢打賭,您目前不這樣做。

換句話說,您需要類似這樣的內容(假設使用ARC)

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

提姆

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM