2015-09-07 22 views
1

我有一個UITableView完整的UICollectionView的。 UICollectionViews需要知道它們包含在哪個UITableViewCell中。我無法弄清楚如何找到這個值。我如何找到父UITableViewCell的索引值?

我做這個標籤分配給每個的UITableViewCell:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell 

    cell.tag = indexPath.row 

    return cell 
} 

我需要檢索標籤在這裏再次:

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

    let tableIndex = //WHAT DO I PUT HERE? 

    return masterArray[tableIndex].count 

} 
+0

是的,我想這也行得通!你能幫我嗎? – bkwebhero

+0

你知道哪個'UITableView'是一個'UICollectionView'屬於你的數據模型。 – zaph

+0

我不太清楚你的意思是...我在學習。你介意闡述嗎? – bkwebhero

回答

1

masterArray應該包含在該部分陣列你可以簡單地寫

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

    let sectionArray = masterArray[section] 
    return sectionArray.count 
} 
+0

我想你可能錯過了這個問題。它不是他在 – Devster101

+0

之後的部分的數量Devster是正確的;我需要TableViewCell的索引。 – bkwebhero

+0

爲了什麼目的? – vadian

0
let tableIndex:Int = 0 
    if let cell = collectionView.superview as? UITableViewCell { 
     if let tableView = cell.superview as? UITableView { 
      if let index = tableView.indexPathForCell(cell)?.row { 
       tableIndex = index 
      } 
     } 
    } 
+0

由於某種原因,這使得我的所有CollectionView返回0。 – bkwebhero