表单元格运行的时间比预期的要短。 (我使用不同的背景颜色来显示宽度的差异)单元格的设置是自定义的(仅行高更改为140)。 playerCell类仅包含一些IBoutlet。谢谢。
(图片:情节提要
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var count: Int
if playerBank.count == 0
{
count = 1
}
else{
count = playerBank.count
}
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! playerCell
if playerBank.isEmpty{
let p = Player()
playerBank = setInvalidPlayer(pBank: p, userInput: userInputPlayerName)
}
let playerInBank: Player = playerBank[indexPath.row]
passImageUrl = cell.setPlayerCell(p: playerInBank)
urlBank.append(passImageUrl)
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.red
cell.selectedBackgroundView = bgColorView
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
myIndex = indexPath.row
DispatchQueue.main.async {
self.performSegue(withIdentifier: "ShowPlayerInfo", sender: self)
}
}
答案 0 :(得分:1)
我的第一个猜测是,尽管您有一个带有自定义插座的自定义单元,但没有适当的布局约束。因此,您放入情节提要中的项目将保留其内在价值,而不适合设备屏幕的大小。
如果您向这些出口添加约束,尤其是在可以根据其余元素确定单元的宽度的地方添加足够的约束,则您的单元应显示完整宽度。