How do you load custom UITableViewCells from Xib files?

前端 未结 23 1985
抹茶落季
抹茶落季 2020-11-22 11:11

The question is simple: How do you load custom UITableViewCell from Xib files? Doing so allows you to use Interface Builder to design your cells. The answer app

23条回答
  •  一个人的身影
    2020-11-22 11:22

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
                let cellReuseIdentifier = "collabCell"
                var cell:collabCell! = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as? collabCell
                if cell == nil {
                    tableView.register(UINib(nibName: "collabCell", bundle: nil), forCellReuseIdentifier: cellReuseIdentifier)
                    cell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! collabCell!
                }
    
    
                return cell
    
    }
    

提交回复
热议问题