我一直在努力解決這個問題。我可以在標籤單元之間自由滾動,因爲它實際上可以記住它們。但是,如果我將描述單元從我的視圖中移出,它會立即將其從內存中移除並且無法恢復。相反,當我回滾到描述時,我只是得到「致命錯誤:意外地發現零,同時展開可選值」。所以,我有以下的代碼片段:Swift - 滾動備份時TableView崩潰
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
tableView.delegate = self
tableView.dataSource = self
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44.0
tableView.reloadData()
}
我不知道,如果是viewWillAppear中在這種情況下,任何重要的,但如果它是那麼告訴我。無論如何,這是在我的表視圖中的細胞填充:
func GetDescription(cell:descCell, indexPath: NSIndexPath) {
cell.descText.text = descriptTextTwo.htmlToString
}
func GetTagCell(cell:basicTag, indexPath: NSIndexPath) {
let item = tagResults[indexPath.row]!
cell.titleLabel.text = item["tagname"]?.htmlToString
}
func GetValueCell(cell: basicTag, indexPath: NSIndexPath) {
let item = tagResults[indexPath.row]!
cell.valueLabel.text = item["value"]?.htmlToString
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if filledDescription == false {
return getDescriptionAtIndexPath(indexPath)
} else {
return getTagAtIndexPath(indexPath)
}
}
func getDescriptionAtIndexPath(indexPath:NSIndexPath) -> descCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier(descriptionCell) as descCell
GetDescription(cell, indexPath: indexPath)
filledDescription = true
return cell
}
func getTagAtIndexPath(indexPath: NSIndexPath) -> basicTag {
let cell = self.tableView.dequeueReusableCellWithIdentifier(tagCell) as basicTag
GetTagCell(cell, indexPath: indexPath)
GetValueCell(cell, indexPath: indexPath)
return cell
}
那麼,怎樣才能讓我想起雨燕是什麼在第一個單元格?因爲我猜測這就是發生了什麼事,一旦你將它從視圖中移出,它就會刪除第一個單元格中的內容。我猜我必須用「indexPath」做些什麼,但我不確定如何在這種情況下實現它,如果我很遠,請告訴我我做錯了什麼。謝謝!
對於哪一行你會得到錯誤? – giorashc 2015-03-31 12:52:48
我沒有收到錯誤。該應用程序構建並啓動。直到我看到這個視圖並開始向下滾動,然後備份應用程序崩潰。 – 2015-03-31 12:55:13
但是,如果您的設備是通過Xcode啓動的,您應該看到一個崩潰日誌,並在跟蹤發生之前爲您提供執行的最後一行......您是否看到一個? – giorashc 2015-03-31 12:59:02