2015-08-13 48 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 
} 
相關問題