ios – The way to separate tableview header and cellForRowAt from identical json in swift

[ad_1]

I need to show countrycode as header of desk view and after click on on header venue ought to show. I had tried however I am unable to realize output as anticipated.

That is my json :

{
  "conferences": [
    {
      "meetingId": 31389393,
      "name": "Ludlow 20th Apr",
      "openDate": "2022-04-20T12:00:00+00:00",
      "venue": "Ludlow",
      "eventTypeId": 7,
      "countryCode": "GB",
      "meetingGoing": "Good"
    },
    {
      "meetingId": 31389469,
      "name": "Catterick 20th Apr",
      "openDate": "2022-04-20T12:40:00+00:00",
      "venue": "Catterick",
      "eventTypeId": 7,
      "countryCode": "GB",
      "meetingGoing": "Good (Good to Soft in places)"
    },
    {
      "meetingId": 31389416,
      "name": "Perth 20th Apr",
      "openDate": "2022-04-20T12:50:00+00:00",
      "venue": "Perth",
      "eventTypeId": 7,
      "countryCode": "GB",
      "meetingGoing": "Good to Soft (Good in places)"
    },
    {
      "meetingId": 31389532,
      "name": "Lingfield 20th Apr",
      "openDate": "2022-04-20T15:15:00+00:00",
      "venue": "Lingfield",
      "eventTypeId": 7,
      "countryCode": "GB",
      "meetingGoing": "Standard"
    },
    {
      "meetingId": 31389447,
      "name": "Salisbury 20th Apr",
      "openDate": "2022-04-20T15:25:00+00:00",
      "venue": "Salisbury",
      "eventTypeId": 7,
      "countryCode": "GB",
      "meetingGoing": "Good to Firm (Good in places)"
    }
  ]
}

Right here is my code which is I am utilizing for getting information:

struct Racing{
    var countryCode:String
    var venue: [String]
}

var todayRacingArray = [Racing]()

for merchandise in response.conferences ?? []
{
   let cc = merchandise.countryCode
   var venue = [String]()
   ven.append(merchandise.venue ?? "")
   let obj = Racing(countryCode: cc ?? "", venue: venue)
   self.todayRacingArray.append(obj)
}
self.otherSportsTableView.reloadData()

TableView:

func numberOfSections(in tableView: UITableView) -> Int {
    return self.todayRacingArray.rely
}

func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int     {
    return self.todayRacingArray[section].venue.rely
}

func tableView(_ tableView: UITableView, viewForHeaderInSection part: Int) -> UIView? {
    let cell =  tableView.dequeueReusableCell(withIdentifier: String(describing: HeaderTableViewCell.self)) as! HeaderTableViewCell
    let obj = todayRacingArray[section]
    cell.titleLbl.textual content = obj.countryCode
    return cell
  }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell =  tableView.dequeueReusableCell(withIdentifier: String(describing: BodyTableViewCell.self)) as! BodyTableViewCell
    cell.body = tableView.bounds
    cell.layoutIfNeeded()
    let obj = self.todayRacingArray[indexPath.section].venue[indexPath.row]
    cell.horseTitleLabel.textual content = obj
    return cell
}

My Output My desk Header After Clicking on header
I need Output like this: enter picture description right here After clicking on header

Please somebody helpme out with this.

[ad_2]

Leave a Reply