0
我有一個UITableView,並且在滾動時產生抖動的tableView的「CellForRowAt」委託函數中包含我自定義UIView的nib文件。例如:在自定義UIView的CellForRowAt中包含nib文件在滾動時產生抖動
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:
"cell", for: indexPath) as! CustomCell
let customView: CustomView = Bundle.main.loadNibNamed("CustomView", owner:
self, options: nil)![0] as! customView
cell.customViewPlacement.addSubview(customView)
return cell
}
如何解決滾動問題和我的代碼中存在的問題? 感謝
不,您錯了。我沒有創建tableViewCell的筆尖。 customView是我放置在單元格中的視圖。 let customView:CustomView = Bundle.main.loadNibNamed(「CustomView」,owner:self,options:nil)![0] as! customView //這是我的自定義視圖............ cell.customViewPlacement.addSubview(customView)//這是我放置自定義視圖的位置。 –
這就是你錯了的地方,你應該創建一個包含那個視圖的單元格,而不是將它們分開,如果你無論如何都不能這麼做,那麼將視圖添加到'CustomCell'類的' awakeFromNib',而不是'cellForRow' – Tj3n