如何获取 collectionviewcell 的选中数 indexpath.row 作为 slideshare

How to get the number of selected indexpath.row of collectionviewcell as slideshare

我想获取集合视图中所选单元格的数量作为下面的幻灯片共享应用 "10/53"

我厌倦了很多方法都错了,例如: "(print[indexpath.row])" 或 print"cell[indexpath.row].count"

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


    // Configure the cell
    if indexPath.row == 0 {
     cell.txxt.text = "Biz memorabilia: 1st day in business, a cold & cloudy day in 1955, @McDonalds did 6.12 in revenue on 2 registers.Biz memorabilia: 1st day in business, a cold & cloudy day in 1955, @McDonalds did 6.12 in revenue on 2 registers."

    }
    if indexPath.row == 1 {
        cell.txxt.text = "SmartHalo: Turn any bike into a smart bike http://www.producthunt.com/tech/smarthalo  via @gozmike on @producthunt"

    }
    if indexPath.row == 2 {
        cell.txxt.text = "Traditionally, policymakers & nonprofits try to improve financial health by measuring & teaching financial literacy"

    }

    //slideNumber is uilabel in the collectionViewCell
    cell.slideNumber.text = "(print[indexpath.row])"

    return cell
}

使用 visibleCells 获取当前可见,for 10 of 53:

   func scrollViewDidScroll(scrollView: UIScrollView!) {

        for cell in collectionView.visibleCells() as [CollectionViewCell] {
            var indexPath : NSIndexPath = collectionView.indexPathForCell(cell as CollectionViewCell)!
            // do something
            // display 10 of 53 here        
        }
    }

单元格中的 10/53

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


    // Configure the cell
    if indexPath.row == 0 {
     cell.txxt.text = "Biz memorabilia: 1st day in business, a cold & cloudy day in 1955, @McDonalds did 6.12 in revenue on 2 registers.Biz memorabilia: 1st day in business, a cold & cloudy day in 1955, @McDonalds did 6.12 in revenue on 2 registers."

    }
    if indexPath.row == 1 {
        cell.txxt.text = "SmartHalo: Turn any bike into a smart bike http://www.producthunt.com/tech/smarthalo  via @gozmike on @producthunt"

    }
    if indexPath.row == 2 {
        cell.txxt.text = "Traditionally, policymakers & nonprofits try to improve financial health by measuring & teaching financial literacy"

    }

    //slideNumber is uilabel in the collectionViewCell
    cell.slideNumber.text =  NSString(format: "%d/%d", indexPath.row, totalCell) // totalCell is num of cells you have

    return cell
}