[英]How can I get a uitableViewCell by indexPath.row or only row number instead of indexpath?
[英]How to get the number of selected indexpath.row of collectionviewcell as slideshare
我想以“ 10/53”下方的幻灯片共享应用的形式在集合视图中获取所选单元格的数量
我厌倦了很多错误的方法,例如:“(print [indexpath.row] .count”)或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 $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
}
对于53中的10,使用visibleCells获取当前可见值:
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.