2015-08-13 44 views
0

标题基本上说明了一切;我想设置一个tableView的委托和数据源,我们将叫myTable。我通常会做到这一点的方法是通过建立从故事板的出口连接表中,然后设置委托和数据源,如:设置UICollectionViewCell中的UITableView集的委托和数据源

@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"

我明白错误,但我的问题是;现在我该如何设置代理和数据源,以至于我的常用方法不可用。

+0

你有没有实现UITableViewDatasource和的UITableViewDelegate? – Antoine

+0

@Tander我想要的是有一个应用程序,将玩家列表分成可变数量的团队(根据他们的评分均匀分配)。我正在制作一个tableView的collectionView,这样我就可以根据所需团队的数量获得可变数量的表格,每个表格都包含玩家的名字。 (它自己的表不在collectionView中,但在collectionViewCell中,如果这是什么让你感到困扰) –

回答

0

好的,所以我想通了。我挂了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 
} 
相关问题