在TableView中使用UIImageView扩展来修复来自startAnimation的UIActivityIndicatorView的问题,可以按照以下步骤进行:
import UIKit
extension UIImageView {
func fixActivityIndicatorBug() {
for subview in self.subviews {
if subview is UIActivityIndicatorView {
subview.removeFromSuperview()
}
}
}
}
cellForRowAt
方法中:func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomTableViewCell
// 先修复UIActivityIndicatorView的问题
cell.imageView?.fixActivityIndicatorBug()
// 设置图片
cell.imageView?.image = UIImage(named: "your_image_name")
return cell
}
这样,当你在TableView中使用UIImageView来显示图片时,就会先修复UIActivityIndicatorView的问题,然后再设置图片。
这个修复方法的原理是遍历UIImageView的子视图,如果发现子视图是UIActivityIndicatorView,则将其从父视图中移除。这样可以避免UIActivityIndicatorView在UIImageView中重复显示的问题。
推荐的腾讯云相关产品:腾讯云移动直播(https://cloud.tencent.com/product/mlvb)可以用于在移动端实时直播中使用UIImageView扩展修复UIActivityIndicatorView的问题。
领取专属 10元无门槛券
手把手带您无忧上云