我已使用此代码
在我的CollectionView上设置了UIRefreshControl
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(ViewController.refreshLoad), for: .valueChanged)
collectionViewIBO.addSubview(refreshControl)
我很难理解的是如何使用刷新。目前,我将didSelectItemAt
与我的模型datasource.model[indexPath.row]
一起使用。我希望能够选择一个随机索引来转换到这个函数内部
func refreshLoad() {
print("refresh")
self.collectionViewIBO.reloadData()
stopRefresher()
}
我知道要使用随机索引Int(arc4random_uniform(UInt32(model.count)))
。但是,如何调用此函数执行与didSelectItemAt
相同的操作?
答案 0 :(得分:0)
如果您正在寻找相同的行为。为什么不创建一个以indexPath作为参数的单独函数。
称之为:
segueToUsing(indexPath : NSIndexPath) {
// Your current didSelectRowAt implementation
}
然后在didSelectRowAt中,只需使用给定的indexPath调用此函数。在refreshLoad
函数中,使用生成的随机indexPath调用此segueToUsing
函数:
let row = Int(arc4random_uniform(UInt32(model.count)))
let indexPath = NSIndexPath(row: row, section: 1)
这将解决1个实现。