Home > other >  Pass data to custom table view header component every second
Pass data to custom table view header component every second

Time:07-03

I have a view controller that uses table view. I created a custom header for this table (UITableViewHeaderFooterView). I need to pass data to this header component. I have a websocket and I received data every second. Everytime I received the data I need to do some logic work and pass it to this component. Right now, I can pass data to this header view on initializing, please see code below. I called a configure function from header view but this only called once. What I need is something that I can use every time a data is changed.

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    guard let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: MarketPricesHeaderView.identifier) as? MarketPricesHeaderView else {
        return nil
    }
    segmentOptionItems = markets?.fetchMarketCurrencyOptions() ?? []
    header.configure(with: .init(segmentItems: segmentOptionItems, segmentWidth: segmentOptionWidth))
    return header
}

CodePudding user response:

You can insert this code inside your update listener

if let header = tableView.headerView(forSection: 0) as? MarketPricesHeaderView {
   header.configure(......
}  
  • Related