Swift 3
Let say you have a tableView which has two types of cell. indexPath.row == 0 will show a header cell & rest of cell are info holder cell. For this you need to do the following things
extension YourControllerName: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourDataHolderArray.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// Specify the height of cell if the cells height are different
if indexPath.row == 0 {
return 30.0
}
return 80.0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if yourDataHolderArray.count > 0 {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell1", for: indexPath) as! YourHeaderCell
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell2", for: indexPath) as! YourInfoCell
return cell
}
}
return UITableViewCell()
}
}
Hope it helps.