2015-07-13 98 views
0

我遇到了tableview問題。當一路到表的末尾,並再次向上,表內容不加載瞬間..Swift - 滾動備份時表空白

這是代碼:

enter image description here

有什麼建議?

+2

請勿使用屏幕截圖。只需複製並粘貼代碼即可。 – Fogmeister

+0

只是一個建議。在第3行中,你將'tableCell'定義爲'UITableViewCell!''因爲在接下來的幾行中你將填充'tableCell'變量,所以你可以聲明它爲'UITableViewCell'而不用'!'。 Infact Swift會檢查你是否總是在使用它之前填充var,並且允許它。 –

+0

另一個建議,如果可能的話,你應該使用'let'而不是'var'。因爲一旦分配'tableCell'不會改變,你應該使用'let'聲明它爲常量。 –

回答

0

好的,我們解決了這個問題。

的問題是在這個代碼:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    if indexPath.row > 22 && !isAll && indexPath.row == signArray.count-1{ 
     //This makes the table load inspections in chunks of 24 meaning alot of smaller DB calls instead of one big one and therefore a better user experience since it reduces load times. 
     signArray = signArray + appDelegate.dbInterface.findInspectionsBySeriesID(signArray[0].seriesID, offset: numberOfLoads*24, limit: 24) 
     numberOfLoads++ 
     tableView.reloadData() 
    } 
} 

的這裏的邏輯是有點瑕疵的,也不管是否有新的數據或不表得到了重新加載。離開上表單元格空白,它仍然是奇怪的,當沒有數據得到,它只會發生,但將其更改爲:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    if indexPath.row > 22 && !isAll && indexPath.row == signArray.count-1{ 
     //This makes the table load inspections in chunks of 24 meaning alot of smaller DB calls instead of one big one and therefore a better user experience since it reduces load times. 
     var newInspections = appDelegate.dbInterface.findInspectionsBySeriesID(signArray[0].seriesID, offset: numberOfLoads*24, limit: 24) 
     if !newInspections.isEmpty{ 
      signArray = signArray + newInspections 
      numberOfLoads++ 
      tableView.reloadData() 
     } 
    } 
} 

解決了這一問題。

+0

嗨,我有同樣的問題,當我向上滾動並保持幾秒鐘,然後單元格消失,釋放後滾動單元格會自動出現,但我仍然沒有找到確切的情況。 –

相關問題