Jam*_* Fu 1 xcode uitableview uiactivityindicatorview ios swift
我有一个包含UIActivityIndicatorView(微调器)的自定义UITableViewCell,我尝试单击该单元格以使微调器开始动画.所以我尝试在UITableViewController中实现以下内容:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.dequeueReusableCellWithIdentifier("testcase", forIndexPath: indexPath) as TestCaseTableViewCell
cell.spinner.startAnimating()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
我的TestCaseTableViewCell(自定义单元类)中有实例变量"spinner":
@IBOutlet weak var spinner: UIActivityIndicatorView!
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
我只想点击单元格,旋转器开始动画,因为我想在这段时间内做点什么.当事情完成后,我可以在单元格中显示类似"OK"的内容(与旋转器的相同位置).我怎样才能做到这一点?
问题在于如何从表视图中检索单元格:dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath).UITableView当您需要显示新单元格时,此方法会从其重用缓存中请求单元格,因此只应在tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)表格视图的数据源的方法中使用.
要询问屏幕单元格的表格视图,请使用cellForRowAtIndexPath(indexPath: NSIndexPath).您的代码示例将变为:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? TestCaseTableViewCell {
cell.spinner.startAnimating()
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2545 次 |
| 最近记录: |