swift - 在表格 View 行的右侧显示事件指示器

标签 swift uitableview uiactivityindicatorview

我的表格 View 将披露指示器作为附件。此 tableview 单元格的 didSelectItem() 调用在后台执行 api 调用。因此 View 需要等到响应才能显示下一页。我必须为披露指示器的位置提供一个事件指示器。怎么可能像在 ios 设置页面中一样

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    // Returns the cell value for each index
    let cell = tableView.dequeueReusableCell(withIdentifier: TenantCell.identifier, for: indexPath) as! TenantCell
    cell.populate(with: tenantList[indexPath.row])
    return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    Api.domain = tenantList[indexPath.row].url!
    sharedAFManager.getJsonData(api: Api.theme, completionHandler: { (response, statusCode) in
        if let theme = response {
            Api.logo = theme["logo"].stringValue
            Constants.passwordRegx = theme["passwordRegex"].stringValue
            self.performSegue(withIdentifier: Segue.login, sender: indexPath.row)
        }
    })
}


/// UITableview cell populating tenant informations
class TenantCell: UITableViewCell {

    @IBOutlet weak var tenantImage: UIImageView!
    @IBOutlet weak var tenantNameLabel: UILabel!
    @IBOutlet weak var tenantUrlLabel: UILabel!

    func populate(with tenant: Tenant) {
        tenantNameLabel?.text = tenant.name
        tenantUrlLabel?.text = tenant.url
        tenantImage.image = UIImage(named: "breifcase")
    }
}

Expected output

最佳答案

请写在cellForRowAt方法中:

cell.accessoryType = .disclosureIndicator

然后在didSelectRowAt方法中请写

guard let cell : TenantCell = (tableView.cellForRow(at: indexPath) as! TenantCell) else {
        return
}
    cell.accessoryView = activityIndi
    activityIndi. startAnimating()

得到响应后

activityIndi. stopAnimating()

也许对你有帮助。谢谢

关于swift - 在表格 View 行的右侧显示事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53993340/

相关文章:

iphone - 事件指示器无法正常工作

Swift,如何实现基于对象引用的Hashable协议(protocol)?

ios - Google Map iOS SDK - 清除可见区域内和不可见区域内的所有标记

ios - UITableView/UIScrollView 改变手指抬起后弹跳的速度

ios - 重新加载 UITableView 数据而不重新定位 UITableViewCells

iphone - 桌面 View 中的自定义标题会降低 iPhone 3G 3.1.3 的速度

ios - 如何在成功连接 NSURL 后关闭警报 View

objective-c - 带有 UIWebView loadRequest 的 UIActivityIndi​​cator?

objective-c - NSWindow +没有圆角的标题栏?

swift - "subscript"的使用不明确