我的tableview細胞字幕沒有顯示時,我用這個:泰伯維細胞字幕
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell:UITableViewCell?
if tableView.tag == 1 {
guard let latestCell = tableView.dequeueReusableCell(withIdentifier: "latestCell") else {
return UITableViewCell(style: .subtitle, reuseIdentifier: "latestCell")
}
latestCell.textLabel?.text = latest[indexPath.row]
latestCell.detailTextLabel?.text = latestSub[indexPath.row]
latestCell.accessoryType = .disclosureIndicator
return latestCell
}
} 不過,如果我用這個:
else if tableView.tag == 2 {
let olderCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "olderCell")
olderCell.textLabel?.text = older[indexPath.row]
olderCell.detailTextLabel?.text = olderSub[indexPath.row]
olderCell.accessoryType = .disclosureIndicator
return olderCell
}
else {
return cell!
}
} 字幕加載完美,但在關閉應用程序並重新加載視圖後,應用程序會自動進行自動處理,而不會提供崩潰日誌或帶我進入調試選項卡。
我知道數據來自的數組很好,我認爲我已經在故事板中設置了一切。關於這個問題已經發布了很多類似的問題,但他們似乎都忘了將cellStyle設置爲.subtitle。預先感謝我獲得的任何幫助!
順便說一句。我的常規單元格標題正如我想要的那樣工作。那裏沒問題。
編輯:
我認爲問題是,我可以創造也沒有問題的默認風格細胞。但是當我嘗試將樣式設置爲.subtitle時,它會在第一次正確加載,但第二次打開時會崩潰。有沒有辦法將這兩個聲明一起使用,以避免互相排斥;?
guard let latestCell = tableView.dequeueReusableCell(withIdentifier: "latestCell") else {
return UITableViewCell(style: .subtitle, reuseIdentifier: "latestCell")
}
和:
let latestCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "latestCell")
A link to a view of how my cells are set up in the storyboard:
在你守護讓的東西,你甚至沒有設置其屬性返回的單元格。第二個代碼不重用單元格(不推薦)。 – Larme
朋友我可以問你嗎?你使用兩個tableview嗎? –
是的,我正在使用兩個。 – Tuomax