我希望能将一个参数传递给一个被定时器调用的函数,该函数作为选择器。具体来说,我需要传递对单元格的引用,以便在用户界面中更新某些内容。所以我想要做的事情类似于这样:
timer = Timer.init(timeInterval: 1.0, target: self, selector: #selector(downloadTimer(cell: cell), userInfo: nil, repeats: true)
函数
func downloadTimer(cell: InnerCollectionCell) {
cell.progressBar.setProgress(downloadProgress, animated: true)
}
虽然我可能有点天真,认为这可以做到?
------ 编辑 ------
根据以下示例,但从单元格中通常无法获得预期结果
let innerCell: InnerCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierInner, for: indexPath) as! InnerCollectionCell
timer = Timer.init(timeInterval: 1.0, target: self, selector: #selector(downloadTimer(_:)), userInfo: innerCell, repeats: true)
func downloadTimer(_ timer: Timer) {
let cell = timer.userInfo
cell. // no options as expected of a cell
}
我希望如果数据被正确发送,会有更多类似这样的选项: