셀을 서브 클래스로 만들려고하는데 프레임 크기가 init()
인 것은 heightForRowAtIndexPath
에서 설정 한 것이 아닙니다.UITableViewCell 하위 클래스에서 사용자 지정보기를 시작할 때?
class MyCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
initCell()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initCell()
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
println("ContentViewFrame IN SET SELECTED: \(self.contentView.frame)")
}
func initCell() {
println("ContentViewFrame IN initCell: \(self.contentView.frame)")
}
}
나는 tabelView에 등록 않습니다
myTable.registerClass(MyCell.self, forCellReuseIdentifier: "awesomeCell")
그것을 사용
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("conversationCell", forIndexPath: indexPath) as ConversationCell
return cell
}
설정 높이를 동적 :
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 100.0
}
이 콘솔 출력 :
ContentViewFrame IN initCell: (0.0,0.0,320.0,44.0)
ContentViewFrame IN SET SELECTED: (0.0,0.0,320.0,99.5)
ContentViewFrame IN SET SELECTED: (0.0,0.0,320.0,99.5)
그래서 초기화 할 때 셀의 높이가 100.0 일 것으로 예상됩니다. 하지만 높이가 44.0이고 함수가 올바른 높이를 반환하는 것은 setSelected
뿐입니다. 셀 초기화의 어떤 단계에서 맞춤 설정을 정의해야합니까? heightForRowAtIndexPath
으로 정의 된 높이의 셀을 사용할 수 있습니까?
왜 initCell()에 높이가 필요한가요? 셀 뷰 구성 요소는 어디에 생성합니까? 델리게이트 메서드를 통해 셀을 만든 후에 설정되므로 init에서 높이를 알 수 없습니다. – bandejapaisa
당신은'layoutSubviews()'에 함수를 넣을 수 있습니다. – Ian
subview를 레이아웃하지 않는 한 layoutSubviews에 아무것도 넣지 않을 것입니다. 먼저 initCell에서 무슨 일이 일어나는지 알아야합니다. – bandejapaisa