问题
Is there any way that I could reload only tableViewCell only but don't make it reload tableView section title View ? when I switched UITableViewCell I want to update data reload change
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
}
What I want to do is just reload UITableViewCell only I don't want to reload this code below
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {}
if I use tableView.reload() it will effected my style in viewForHeaderInSection Because I have added UIViewScroll
thank you for your help!
回答1:
If you want to reload only particular tableView cell then use this:
tableView.reloadRows(at: [IndexPath(row: rowNumber, section: 0)], with: .automatic)
It reload only cell not the section.
回答2:
Reload the Particular UITableViewCell
tableviewCart.reloadRows(at: [indexPath!], with: .none)
回答3:
Look for the table view delegate methods for reloading views. These are:
open func reloadSections(_ sections: IndexSet, with animation: UITableView.RowAnimation)
open func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)
open func reloadData()
Here in your case, reloadRows
will be the best suitable option, as:
tableView.reloadRows(at: <[IndexPath]>, with: .automatic)
Where, <[IndexPath]>
is the array of index path of the cells. For example:
let cell0FromSection0 = IndexPath(row: 0, section: 0)
let cell2FromSection0 = IndexPath(row: 2, section: 0)
let cell1FromSection1 = IndexPath(row: 1, section: 1)
tableView.reloadRows(at: [cell0FromSection0, cell2FromSection0, cell1FromSection1], with: .automatic)
来源:https://stackoverflow.com/questions/43567995/how-to-reload-tableviewcell-only-in-swift