2015-07-28 86 views
0

我想要在另一个tableviewCell里面使用tableview,就像下面的image中的一样。它显示了一个完整的单元格,其中有一些细节和一个tableview。我该如何做到这一点?我正在关注这个链接Link。这是一个旧的代码。它使用xibs.I没有任何想法在哪里设置内部tableview的代表。请help.Any建议将是真正有用的。 enter image description here在另一个UItableviewCell里面的UItableview

+0

显示您尝试的代码? – Matt

回答

1

我的第一个想法是:

  1. 子类的UITableViewCell( “MainTableViewCell”),并与的UITableViewDelegate和UITableViewDatasource扩展它。

  2. 在“MainTableViewCell”中添加一个TableView“tableViewFilms”和一个数组“电影”。另外不要忘记将tableview的数据源方法添加到实现文件中。 为了方便地设置单元格,我在头文件中添加了一个setup-method。一旦细胞被实例化,可以调用它。您可以根据需要修改它,根据需要为其提供尽可能多的参数,并在实现中(请参阅步骤4)设置内部tableview的数据源和委托。

    - (void)setupCellWithDictionary:(NSDictionary *)dict AndArray:(NSArray *)filmsForInnerTable; 
    

    您可以在数据源的方法调用此方法,一旦细胞被实例化:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
        MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainTableViewCell" forIndexPath:indexPath]; 
    
        NSDictionary *dict = (NSDictionary *) allDataDictionaries[indexPath.row]; 
        [cell setupCellWithDictionary:dict AndArray:filmsForInnerTable]; 
    
        return cell; 
    } 
    
  3. 子类的UITableViewCell另一次: “FilmTableViewCell”

  4. 当设置单元格“MainTableViewCell”,将“tableViewFilms”的委托和数据源设置为self(“MainTableViewCell”的对象)。

    - (void)setupCellWithDictionary:(NSDictionary *)dict AndArray:(NSArray *)filmsForInnerTable{ 
        self.films = filmsForInnerTable; 
        self.tableViewFilms.dataSource = self; 
        self.tableViewFilms.delegate = self; 
        [self.tableView reload]; 
        //more instructions 
    } 
    
  5. 填充使用 “FilmTableViewCells” 与从阵列 “膜” 的数据的tableview。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
        FilmTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FilmTableViewCell" forIndexPath:indexPath]; 
    
        Film *film = (Film*)films[indexPath.row]; 
        [cell setupCellWithFilm:film]; 
    
        return cell; 
    } 
    

希望这有助于。

不要忘记使用Outlets,方法定义并设置单元格的重用标识符!

+0

你能解释第四点吗? – iosDeveloper

+0

你是说MainTableViewCell.m应该有内部表的数据源方法吗?如果是这样,我怎样才能将数据从mainViewController传递到MainTableViewCell.I已经尝试了很多方法。是否有任何init方法? – iosDeveloper

+0

我编辑了我的答案,这应该对你有所帮助,而且你应该能够找到自己的方式。 Sry为错别字,我在这里写了一切,没有测试它。 – dfinki

1

查看我的回答ios 8 Swift - TableView with embedded CollectionView。你已经用UITableView取代了UICollectionView。其他一切都差不多。它只是以编程方式创建的UITableView和UICollectionView。

如果您不明白,我可以相应地更改它。

+0

我不熟悉swift。你能解释一下逻辑吗? – iosDeveloper