gpt4 book ai didi

ios - tableView 中的函数 :cellForRowAtIndexPath: only called for the first 2 cell

转载 作者:行者123 更新时间:2023-11-28 15:49:21 24 4
gpt4 key购买 nike

所以我有这个功能:

func addActivityIndicator(_ aspectRatio: CGFloat?, index: Int) {
if activityIndicator == nil {
print("add activity indicator")
print("at index: \(index)")
let screenWidth = UIScreen.main.bounds.width
let height: CGFloat
if let aspectRatio = aspectRatio {
height = screenWidth / aspectRatio
} else {
print("aspect ratio is nil")
height = screenWidth
}
let indicatorFrame = CGRect(x: (screenWidth - 60) / 2,
y: (height - 60) / 2,
width: 60,
height: 60)

self.activityIndicator = NVActivityIndicatorView(frame: indicatorFrame,
type: .ballClipRotateMultiple,
color: .lightGray,
padding: nil)
self.addSubview(self.activityIndicator!)
self.activityIndicator?.startAnimating()
}
}

基本上只是在 super View 的中心添加了一个事件指示器。然后我在 cellForRow:AtIndexPath:

中调用了这个函数
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let contentCell = tableView.dequeueReusableCell(withIdentifier: "ContentCell", for: indexPath) as! ContentCell
contentCell.thumbnail.addActivityIndicator(content.aspectRatio, index: indexPath.row)

return contentCell
}

thumbnail 是一个 uiimageview,它将添加一个事件指示器。但在日志中我只看到这个:

add activity indicator at index: 0

add activity indicator at index: 1

add activity indicator at index: 2

如何使 addActivityIndi​​cator 函数适用于所有单元格?

最佳答案

在 ContentCell 的 func awakeFromNib 上添加 ActivityIndi​​cator

关于ios - tableView 中的函数 :cellForRowAtIndexPath: only called for the first 2 cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42536501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com