작동하지 않습니다있는 UITableViewCell을 추가스위프트 프로그래밍이 코드가 제대로
class Cell:UITableViewCell {
var fullName:UILabel! = UILabel()
var userImage:UIImage! = UIImage()
override func awakeFromNib() {
super.awakeFromNib()
println("wake")
fullName.setTranslatesAutoresizingMaskIntoConstraints(false)
contentView.addSubview(fullName)
let imageView = UIImageView(image: userImage)
contentView.addSubview(imageView)
var viewsDict = [
"fullName" : fullName,
"userImage" : userImage
]
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[userImage(10)]", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[fullName]-[userImage(10)]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
}
}
의 viewDidLoad :
이var tableView = UITableView()
tableView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height-64)
tableView.delegate = self
tableView.dataSource = self
var cell = Cell.self
tableView.registerClass(cell, forCellReuseIdentifier: "cell")
self.view.addSubview(tableView)
cellForRowAtIndexpath :
let cell:Cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as Cell
cell.fullName.text = testarray.objectAtIndex(indexPath.row) as? String
return cell
내가 레이블을 볼 수 없습니다 셀에서 심지어 코드를 실행할 때 심지어 println ("wake") 클래스 셀에서 실행되지 않습니다.
프로그래밍 방식으로 셀을 생성한다고 말했을 때. 그러면 'awakeFromNib()'메소드가 그림에 포함되지 않습니다. – Kampai