使用Pull to Refresh搜索随机索引?

时间:2017-01-17 18:53:02

标签: ios swift indexing uicollectionview refresh

我已使用此代码

在我的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相同的操作?

1 个答案:

答案 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个实现。