2017-04-23 69 views
0

有沒有什麼辦法,我可以重新加載只有tableViewCell,但不要重新加載tableView節標題視圖?當我切換的UITableViewCell我想更新數據重裝變化如何僅在swift中重載tableViewCell?

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     switch self[selectedIndex] { 

     case .tracks: 

     let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! TracksCell 
     return cell 

     case .playlists: 

      let cell = tableView.dequeueReusableCell(withIdentifier: cellPlayListId, for: indexPath) as! PlaylistCell 

     return cell 

     } 

我想要做的就是重新加載的UITableViewCell只是我不想,如果我使用的tableView重裝下面

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {} 

此代碼。重載()它會影響我的風格viewForHeaderInSection因爲我已經添加UIViewScroll

謝謝你的幫助!

回答

4

如果你想重裝只有特定的tableView細胞,然後使用此:

tableView.reloadRows(at: [IndexPath(row: rowNumber, section: 0)], with: .automatic) 

它重裝不僅小區的部分。

+0

什麼是rowNumber? – Kristoff

+0

@Kristoff聲明是func reloadRows(在indexPaths:[IndexPath]中,其中animation:UITableViewRowAnimation),其中indexPath是標識要重新加載的行的NSIndexPath對象數組。 – user3441734

+0

@Kristof rowNumber表示您想要重新加載哪個單元格的數量。如果你想重新加載單元格號碼2,那麼你寫的就像。 tableView.reloadRows(at:[IndexPath(row:2,section:0)],with:.automatic) –