많은 사용자 지정 셀 (xib 파일 + UITableViewCell의 신속한 하위 클래스)이 있고 많은 장면에서이를 동적 셀로 사용하고 모든 것이 잘 작동합니다 (셀 등록, 큐 제거 등).프로그래밍 방식으로 사용자 정의 정적 셀
해당 셀을 사용할 수있는 정적 tableView가 필요할 때 제 문제가 발생합니다. 스토리 보드를 사용하여 재사용 가능성을 잃어 버리기 때문에이 작업을 수행하고 싶지 않습니다.
나는 아래와 같이 시도했지만 보통 UITableViewCell
으로, 내 설계된 xib CustomCell
대신에 표시됩니다. 펜촉의 셀 하위 뷰는로드되지 않는 것 같습니다.
private lazy var cells: [UITableViewCell] = [
CustomCell1(),
CustomCell2(),
CustomCell3(),
]
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cells.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return cells[indexPath.row]
}
프로그래밍 방식으로 정적 사용자 지정 셀을 사용하여 UITableView
을 만드는 방법은 무엇입니까?
수정 @thedp에 대한 답변입니다. 맞춤형 셀은 이와 같이 설계되었습니다. 이것은 단지 예입니다 :
final class CustomCell: UITableViewCell {
@IBOutlet weak private var titleLabel: UILabel!
@IBOutlet weak private var textView: MyCustomTextView!
@IBOutlet weak private var doneButton: MyCustomButton!
func configureCell(with: ...) { ... }
}
'CustomCell'에 대한 코드를 공유 할 수 있습니까? – thedp
@thedp 주제 편집 : 관심을 보여 주셔서 고마워요. –