save selected row in UITableView after reloadData

后端 未结 14 936
后悔当初
后悔当初 2020-12-24 11:20

I write custom jabber client in iphone.

I use xmppframework as engine.

And I have UITableViewController with NSMutableArray for repesent contact list.

<
相关标签:
14条回答
  • 2020-12-24 12:24

    SWIFT 3:

    self.collectionView.reloadData()
    self.collectionView.selectItem(at: indexPath, animated: false, scrollPosition: [])
    
    0 讨论(0)
  • 2020-12-24 12:27

    Swift 4.2 Tested

    The correct way to update selected rows after reload table view is:

    let selectedRows = tableView.indexPathsForSelectedRows
    
    tableView.reloadData()
    
    DispatchQueue.main.async {
        selectedRows?.forEach { selectedRow in
            tableView.selectRow(at: selectedRow, animated: false, scrollPosition: .none)
        }
    }
    
    0 讨论(0)
提交回复
热议问题