我知道将 activityIndicator 添加到 View 中的某个位置,在需要时启动和停止动画。但在我的应用程序中的某些情况下,用户单击一个单元格(带有标题和副标题)时,我会在后台获取一些数据,然后向用户显示警告以获取一些输入。在所有这些情况下,我只是在中间显示一个事件指示器,看起来不太好。因此,我只想在用户单击的单元格末尾显示事件指示器。有没有办法做到这一点?
我能想到的一件事是使用自定义表格 View Cell,然后在其中显式添加事件指示器。但是是否可以对标准标题和副标题单元格执行相同操作,并且可以根据用户单击的单元格位置动态重新定位事件指示器?
最佳答案
我认为您可以使用 UITableViewCell 的 accessoryView
var selectedIndexPath : NSIndexPath?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
// ...
if (indexPath == selectedIndexPath)
{
cell.accessoryView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
(cell.accessoryView as! UIActivityIndicatorView).startAnimating()
}
else
{
cell.accessoryView = nil
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
selectedIndexPath = indexPath
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
关于swift - 在 Swift 2.0 的 UITableView 中动态移动事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32881888/