1
我的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。預先感謝我獲得的任何幫助!
順便說一句。我的常規單元格標題正如我想要的那樣工作。那裏沒問題。
我無法返回super.tableview,Xcode不會允許它。除此之外,我改變了代碼,但它仍然沒有顯示字幕,但它也沒有崩潰。感謝您的回覆! – Tuomax
你有什麼補充或其他解決方案嗎? – Tuomax
抱歉沒有早點回來。它看起來應該可以工作 - 也許在'cell.detailTextLabel?.text = latestSub [indexPath.row]'之後設置一個斷點,然後在lldb中輸入'p cell.detailTextLabel?.text'來查看它是否設置正確。當你在它的時候輸入'p latestSub [indexPath.row]'來查看你的數組是否正確填充。 – joeybladb