gpt4 book ai didi

ios - 如何获取 collectionviewcell 的选定 indexpath.row 的数量作为 slideshare

转载 作者:行者123 更新时间:2023-11-28 07:00:11 25 4
gpt4 key购买 nike

我想在 “10/53”

下获取 Collection View 中选定单元格的数量作为幻灯片共享应用程序

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

enter image description here

     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 $366.12 in revenue on 2 registers.Biz memorabilia: 1st day in business, a cold & cloudy day in 1955, @McDonalds did $366.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 获取当前可见,对于 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 $366.12 in revenue on 2 registers.Biz memorabilia: 1st day in business, a cold & cloudy day in 1955, @McDonalds did $366.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
}

关于ios - 如何获取 collectionviewcell 的选定 indexpath.row 的数量作为 slideshare,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32239414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com