【问题标题】:setting Delegate and datasource of a UITableView set inside a UICollectionViewCell在 UICollectionViewCell 中设置 UITableView 的委托和数据源
【发布时间】:2015-11-05 21:48:43
【问题描述】:

标题基本上说明了一切;我想设置我们将调用myTable 的tableView 的委托和数据源。我通常这样做的方法是从情节提要建立与表的出口连接,然后设置委托和数据源,如下所示:

@IBOutlet weak var myTable: UITableView!

override func viewDidLoad() 
{
    super.viewDidLoad()

    myTable.delegate = self
    myTable.dataSource = self
}

但是,由于我的表位于 UICollectionView 的单元格内,我收到了错误 "The myTable Outlet from the myCollectionViewController to the UITableView is invalid. Outlets Cannot be connected to repeating content"

我理解错误,但我的问题是;既然我常用的方法不可用,我该如何设置委托和数据源。

【问题讨论】:

  • 你实现了 UITableViewDatasource 和 UITableViewDelegate 了吗?
  • @Tander 我想要的是有一个应用程序,可以将玩家列表分成不同数量的团队(均匀地,根据他们的评分)。我正在制作 tableViews 的 collectionView,以便我可以根据所需的团队数量拥有可变数量的表格,每个表格都包含球员姓名。 (它自己的表不在collectionView中,而是在collectionViewCell中,如果这就是困扰你的话)

标签: ios uitableview delegates uicollectionview swift2


【解决方案1】:

好的,所以我想通了。我在 collectionViewCell 类中链接了myTable 插座(我们将调用myCollectionViewCell)并在collectionView: cellForItemAtIndexPath: 方法中设置它的委托和数据源,如下所示

  override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! myCollectionViewCell

    // Configure the cell

    cell.myTable.dataSource = self
    cell.myTable.delegate = self

    return cell
}

【讨论】:

    猜你喜欢
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2010-12-10
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    相关资源
    最近更新 更多