我正在編寫一個應用程序,只是爲了好玩和改進。3具有公共數據源和委託的TableView - 錯誤的行數
我的問題是下列之一:
在我的應用程序的視圖控制器,我有3個tableViews共享數據源和委託(將它的viewController個體經營)。我爲每個做了3個插座,通過這種方式,我可以通過對象參考比較(tableView === outletTableView
)確定numberOfRowsInSection
和cellForRowAtIndexPath
的返回值。 每次都返回正確的值(用某個調用打印進行檢查),但設備似乎使用一個tableView中的numberOfRows作爲3個tableViews! 我的第一個有13行,第二個21和第三隻1.當第二的tableView的第14行被加載,這個錯誤的程序崩潰:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath: 0xc000000001a00016> {length = 2, path = 0 - 13})'
我查過很多科目,但我沒有發現任何解決方案...
感謝
這裏我的代碼:
@IBOutlet weak var mainSkillTableHeight: NSLayoutConstraint!
@IBOutlet weak var secondarySkillTableHeight: NSLayoutConstraint!
@IBOutlet weak var exoticSkillTableHeight: NSLayoutConstraint!
[...]
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (tableView === mainSkillsTable) {
print("CM \(character.main_skills.count + 1)")
return character.main_skills.count + 1
}
else if (tableView === secondarySkillsTable) {
print("CS \(character.secondary_skills.count + 1)")
return character.secondary_skills.count + 1
}
else if (tableView === exoticSkillsTable) {
print("CE \(character.exotic_skills.count + 1)")
return character.exotic_skills.count + 1
}
return 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell1: CreationMainSkillCell?
var cell2: CreationSecondarySkillCell?
var cell3: CreationExoticSkillCell?
if (tableView === mainSkillsTable) {
if indexPath.row == 0 {
return mainSkillsTable.dequeueReusableCellWithIdentifier("mainHeader", forIndexPath: indexPath) as! HeaderMainSkillCell
}
cell1 = mainSkillsTable.dequeueReusableCellWithIdentifier("mainDataC", forIndexPath: indexPath) as? CreationMainSkillCell
cell1!.character = character
cell1!.row = indexPath.row
return cell1!
}
else if (tableView === secondarySkillsTable) {
if indexPath.row == 0 {
return mainSkillsTable.dequeueReusableCellWithIdentifier("secondHeader", forIndexPath: indexPath) as! HeaderSecondarySkillCell
}
cell2 = mainSkillsTable.dequeueReusableCellWithIdentifier("secondDataC", forIndexPath: indexPath) as? CreationSecondarySkillCell
cell2!.character = character
cell2!.row = indexPath.row
return cell2!
}
else if (tableView === exoticSkillsTable) {
if indexPath.row == 0 {
return mainSkillsTable.dequeueReusableCellWithIdentifier("exoticHeader", forIndexPath: indexPath) as! HeaderExoticSkillCell
}
cell3 = mainSkillsTable.dequeueReusableCellWithIdentifier("exoticDataC", forIndexPath: indexPath) as? CreationExoticSkillCell
cell3!.character = character
cell3!.row = indexPath.row
return cell3!
}
return UITableViewCell()
}
numberOfRows沒有鏈接到一個特定的tableView?
如果共享一個公共數據源,行數會有多少? – pbush25
你能給詳細的工具嗎?我認爲問題是你的代碼錯誤的每種表? –
你可以發佈你的代碼嗎? –