我有一個用2個原型單元格創建的UITableView,每個原型單元格都有獨立的標識符和子類。具有多個原型單元格的Swift TableView不顯示所有行
我的問題是當我顯示細胞的第一個原型單元格的第二個原型的第一行被吸收。
例如,我有第一個原型單元格只顯示1項。第二個原型單元應顯示4個項目。但是,第二個原型單元格中的第一項不顯示,相反,只有三個可見的四個項目。
這裏是我的實現代碼:
override func viewDidLoad() {
super.viewDidLoad()
self.staticObjects.addObject("Please...")
self.objects.addObject("Help")
self.objects.addObject("Me")
self.objects.addObject("Thank")
self.objects.addObject("You")
self.tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.objects.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(indexPath.row==0){
let staticCell = self.tableView.dequeueReusableCellWithIdentifier("staticCell", forIndexPath: indexPath) as! StaticTableViewCell
staticCell.staticTitleLabel.text = self.staticObjects.objectAtIndex(indexPath.row) as? String
return staticCell
}
else{
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! PillarTableViewCell
cell.titleLabel.text = self.objects.objectAtIndex(indexPath.row) as? String
return cell
}
感謝所有幫助。
感謝這個幫助。它是完全有道理的,我感謝你的努力。我在離開一段時間後發現問題。再次感謝。 – Rico
@Rico不客氣。很高興聽到你明白了;逐步遠離問題總是有幫助的。 :) – whyceewhite
它是怎麼回事我實現了上面的代碼,並通過打印出迄今爲止的5(這是正確的)的計數做了一些檢查。一切工作,直到我實現計數邏輯,它將兩個細胞計數加在一起。我收到一個NSException和一個SIGABRT信號。不知道爲什麼會這樣。對我來說,似乎計數是超載或溢出。你有什麼想法嗎?感謝 – Rico