繁体   English   中英

另一个UItableviewCell内部的UItableview

[英]UItableview inside antother UItableviewCell

我想要另一个tableviewCell内的tableview, 如下图。它显示了一个完整的单元格,其中包含一些细节和一个tableview。 我该怎么做?我正在跟踪此链接Link 。这是一个旧代码,它使用的是xibs。我不知道在哪里设置内部tableview的委托。请帮助。任何建议都会非常有帮助。 在此处输入图片说明

带有嵌入式CollectionView的ios 8 Swift-TableView中检查我的答案。 您已用UITableView替换了该UICollectionView。

其他所有内容都差不多。 它只是以编程方式创建的UITableView和UICollectionView抢先一步。

如果您不了解,我可以相应地更改它。

我的第一个想法是:

  1. 子类化UITableViewCell(“ MainTableViewCell”),并使用UITableViewDelegate和UITableViewDatasource对其进行扩展。

  2. 在“ MainTableViewCell”中所需的所有属性旁边,添加一个TableView“ tableViewFilms”和一个Films数组“ films”。 同样不要忘记将表视图的数据源方法添加到实现文件中。 为了轻松设置单元格,我将设置方法添加到头文件中。 实例化单元格后可以调用该方法。 您可以根据需要对其进行修改,并为其提供尽可能多的参数,并在实现中(请参阅第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,方法定义并为单元设置重用标识符!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM