2
신속한 놀이터 iPad 앱의보기 컨트롤러에서 만든 테이블보기에 일부 맞춤형 셀을 구현하려고했습니다. 유사한 문제를 다루는 다른 스택 오버 플로우 게시물을 많이 보았지만 내 문제를 해결하는 솔루션을 찾을 수 없었습니다.UITableViewCell이 데이터를 표시하지 않습니다 - 스위프트 놀이터
여기 내 CustomCell 클래스입니다 :
class AboutViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let tableView = UITableView()
let cellReuseIdentifier: String = "cell"
var projectTitles = ["Madhubani Coffee", "World Savvy", "Zipshare", "CrashThatCode", "Future Plans"]
var images: [UIImage] = [UIImage(named: "IMG_0061.JPG")!, UIImage(named: "IMG_0064.JPG")!, UIImage(named: "IMG_0062.JPG")!, UIImage(named: "IMG_0062.JPG")!, UIImage(named: "IMG_0062.JPG")!]
override func viewDidLoad() {
view.backgroundColor = UIColor.white
tableView.frame = CGRect(x: -82.5, y: 250, width: 600, height: 600)
tableView.delegate = self
tableView.dataSource = self
tableView.backgroundColor = UIColor.white
self.tableView.register(CustomCell.self as AnyClass, forCellReuseIdentifier: cellReuseIdentifier)
view.addSubview(tableView)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath) as! CustomCell
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: cellReuseIdentifier) as! CustomCell
}
cell.projectImage.image = images[indexPath.row]
cell.projectTitle.text = projectTitles[indexPath.row]
cell.clipsToBounds = true
return cell
}
}
나는 문제가 무엇인지 모르는 :
class CustomCell: UITableViewCell {
let projectImage = UIImageView()
//let projectDivider = UIView()
let projectTitle = UILabel()
override func awakeFromNib() {
projectImage.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
//projectDivider.frame = CGRect(x: 100, y: 0, width: 20, height: 100)
projectTitle.frame = CGRect(x: 120, y: 0, width: 200, height: 100)
self.contentView.addSubview(projectImage)
//self.contentView.addSubview(projectDivider)
self.contentView.addSubview(projectTitle)
}
}
다음은 내보기 컨트롤러 코드입니다. 세포가 단순히 표시되지 않는 것 같습니다. 어떤 도움을 주시면 감사하겠습니다!