Tom*_*m K 1 uikit ios swift swift3 swift3.2
我迷路了.我搜索并搜索,找不到我的自定义单元格未显示的原因.
// ProfileCell.swift:
import UIKit
import QuartzCore
class ProfileCell: UITableViewCell {
@IBOutlet weak var profileNameLabel: UILabel!
@IBOutlet weak var profilePictureView: UIImageView!
}
Run Code Online (Sandbox Code Playgroud)
第二个默认TableViewCell正常显示.我在Interface Builder或任何错误中没有遗漏约束.在ProfileCell.xib标识选项卡中选择ProfileCell作为自定义类.
// MoreTableViewControllerIB.swift
import UIKit
class MoreTableViewControllerIB: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// this cell is missing
if indexPath.row == 0 {
tableView.register(UINib(nibName: "ProfileCell", bundle: nil), forCellReuseIdentifier: "ProfileCell")
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCell", for: indexPath) as! ProfileCell
cell.profileCommentLabel.text = "Test Comment Label"
cell.profilePictureView.image = UIImage(named:"profile_picture_test")
return cell
// this cell is displayed perfectly
}else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "statisticsCell") ?? UITableViewCell(style: .default, reuseIdentifier: "statisticsCell")
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.textLabel?.text = "Statistics"
cell.imageView.image = UIImage(named:"statistics")
return cell
// has to return a cell in every scenario
}else{
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
return cell
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
tableView.register(UINib(nibName: "ProfileCell", bundle: nil), forCellReuseIdentifier: "ProfileCell")
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad或viewWillApppear中添加此行
| 归档时间: |
|
| 查看次数: |
672 次 |
| 最近记录: |