我收到此錯誤。 我正在使用SQLite。我有一些數據,我想在部分顯示數據,所以我添加了一個列,這將是我的部分名稱,稱爲「cittaTerritorio」。 現在我取回我的數據,當我運行與此消息的代碼一切都崩潰使用此列, 排序是:UITableView無法識別NumberOfRowsInSection
- [UIView的的tableView:numberOfRowsInSection:]:無法識別的選擇發送到實例0x101c3ce50 2017- 10-14 17:14:44.893258 + 0200 MinistryHelp [403:44322] *由於未捕獲異常'NSInvalidArgumentException',原因:' - [UIView tableView:numberOfRowsInSection:]:無法識別的選擇器發送到實例0x101c3ce50' *首先擲出調用堆棧: (0x1812b3d38 0x1807c8528 0x1812c11f8 0x18aa7bcc4 0x1812b96e4 0x18119f0dc 0x18aa02cc8 0x18a7908d8 0x18a7900a4 0x18a78fe34 0x18a7 8fc44 0x18a81c14c 0x1008cfc60 0x1008cf040 0x1008cfedc 0x18a6c3bfc 0x18a76c128 0x18a76b5c8 0x18a76afcc 0x18a76aa34 0x18a76a95c 0x18a6c1000 0x1852910b4 0x185295194 0x185203f24 0x18522a340 0x18522b180 0x18125b8b8 0x181259270 0x18125982c 0x18117a2d8 0x18300bf84 0x18a727880 0x1008c62d0 0x180c9e56c) 的libC++ abi.dylib:與類型的未捕獲的異常終止NSException
你有什麼理念?這是我的代碼:
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.listCitta()[section]
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.territoriInCitta(section: section).count
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.listCitta().count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.listCitta().count
}
func territoriInCitta(section: Int)-> [String]{
let nomeSezione = tableview.headerView(forSection: section)?.textLabel?.text
var listaCitta = [String]()
listaCitta.removeAll()
do{
let territori = try self.database.prepare(territoryTable.filter(cittaTerritorio == nomeSezione!))
for territorio in territori{
listaCitta.append(territorio[self.cittaTerritorio])
}
}catch{
print(error)
}
return listaCitta
}
func listCitta()-> [String]{ //aggiunge i vari nomi delle citta
var listaCitta = [String]()
listaCitta.removeAll()
do{
let terr = try self.database.prepare(territoryTable.select(cittaTerritorio))
for territorio in terr{
if listaCitta.contains(territorio[self.cittaTerritorio]){
//nil
}
else{
listaCitta.append(territorio[self.cittaTerritorio])
}
}
}catch{
print(error)
}
return listaCitta
}
與第一功能我得到基於列表我的方法返回的指數部分的名稱。 第二個函數根據該部分返回數據的數量,所以我根據該部分的名稱過濾數據,並使用列表返回數字。 第三種和第四種方法返回部分的數量。
我也嘗試插入假數據,爲測試目的寫一個數字,沒有什麼不同。
'numberOfRowsInSection'的簽名是錯誤的。註釋掉方法並使用代碼完成重新輸入它,或者查看[UITableViewDataSource](https://developer.apple.com/documentation/uikit/uitableviewdatasource)文檔中的方法。 – vadian
PS:並且**從不**在'numberOfRows'和'numberOfSections'中執行數據庫操作。這些方法經常被調用。創建一個數據源數組並獲取一次數據。 – vadian
我看到問題出在某種程度上,我有2個numberOfRowsInSection方法 – John