Subin K Kuriakose
Subin K Kuriakose

Reputation: 849

uitableview header view issue

I created a tableview and i have 2 sections. in second section i need a header . so i did this like below.

  func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    if section == 1 {
        return 40
    }
    return 0
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if section == 1 {
        let header = tableView.dequeueReusableCellWithIdentifier("audiocellheader")! as UITableViewCell

        return header
    }
    else {
        return nil
    }
}

I have a problem when i reload the section.Header get disappeared.if i do tableview.reload its works fine. what will be the issue?. Also i have an issue when i delete the item in the cell. image is given below.
enter image description here

header get moves as same as edited row.

Upvotes: 2

Views: 683

Answers (1)

Subin K Kuriakose
Subin K Kuriakose

Reputation: 849

I checked the link from here Swipe to delete cell causes tableViewHeader to move with cell got the answer.

instead of cell return cell.contentview.both issue resolved

       func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if section == 1 {
               let header = tableView.dequeueReusableCellWithIdentifier("audiocellheader")! as UITableViewCell
               return header.contentView
        }   
        else {
             return nil
        }
      }

Upvotes: 1

Related Questions