uitableview 셀 안에 tableview를 넣는 데 문제가 있습니다. 지금은 중첩 된 테이블 뷰를 표시하지 않습니다. 테이블 뷰의 델리게이트와 데이터 소스를 커스텀 셀에 설정하고 필요한 모든 메소드를 가지고 있습니다. 나는 또한 내 tableviews에 대한 스토리 보드를 사용하고 모든 콘센트를 제대로 연결했습니다.Tableview를 UITableViewCell Swift 내부에 넣기
문제는 cellforrow 기능에 포함되지 않는다는 것입니다. 그러나 numberofrowsinsection 함수와 heightforrow 함수로 들어갑니다. 아래는 중첩 된 uitableviewcell을 보유하는 사용자 정의 셀의 코드입니다.
수입 UIKit
클래스 EventSurveyCell :있는 UITableViewCell, UITableViewDelegate, UITableViewDataSource는 {
@IBOutlet weak var cellBox: UIView!
@IBOutlet weak var announcementLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var authorLabel: UILabel!
@IBOutlet weak var numVotesLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
var surveyArray: [SurveyClass] = []
override func awakeFromNib() {
super.awakeFromNib()
tableView.delegate = self
tableView.dataSource = self
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
tableView.delegate = self
tableView.dataSource = self
// Configure the view for the selected state
}
func do_table_refresh()
{
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
return
})
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print("cellforrow")
let cell: SurveyItemCell = self.tableView.dequeueReusableCellWithIdentifier("surveyItemCell") as! SurveyItemCell!
cell.itemLabel.text = surveyArray[indexPath.row].itemName
//go through firebase to check which one user voted on
cell.voteButton.imageView!.image = UIImage(named: "circle")
let percent = surveyArray[indexPath.row].numOfVotes/surveyArray[indexPath.row].totalNumOfVotes
cell.precentLabel.text = String(percent)
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
print("heightforrow")
return 44
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("numrowsinsection")
return 3
//should be return self.surveyArray.count.
}
}는 다음
을 포함하여의 ViewController에서 사용자 정의 세포를 들고 그것을위한 코드 조각은 (이다 중첩 된 테이블 뷰). 이 코드는 cellforrowatindexpath경우 PostType.survey의 일부입니다
let cell: EventSurveyCell = self.tableView.dequeueReusableCellWithIdentifier("EventSurveyCell") as! EventSurveyCell!
//cut out other code as it is irrelevant
cell.surveyArray = eventPost.surveyClassArray
cell.do_table_refresh()
print(cell.tableView.rowHeight)
return cell
내가 발견 한 또 다른 문제는 cell.tableview.rowheight을 인쇄 할 때, 그것은 -1을 출력한다는 것입니다. 이것은 cellforrowatindexpath에 들어 가지 않는 이유 일 수 있지만, 확실히 heightforrow 함수에서 44를 반환합니다. 지금은 중첩 된 테이블 뷰를 표시하지 않습니다.