I want to get lines of separation between every two table view cells, but not to create extra sections which I do not need.
For example:

TableViewCell.StackView.UIView at the bottom of the StackView and set a height constraint to the size of the whitespace you require (i.e 10px).StackView height Constraintclass CustomCell: UITableViewCell {
@IBOutlet weak var cellLabel: UILabel!
@IBOutlet weak var bottomSpace: UIView!
@IBOutlet weak var stackViewHeight: NSLayoutConstraint!
}

In viewDidLoad:
tableView.estimatedRowHeight = UITableViewAutomaticDimension
tableView.separatorStyle = .none
In your cellForRowAtIndexPath:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell") as? CustomCell else { return UITableViewCell() }
if indexPath.row % 2 == 0 {
cell.bottomSpace.isHidden = true
cell.stackViewHeight.constant = 70.0 //Normal cell height
} else {
cell.bottomSpace.isHidden = false
cell.stackViewHeight.constant = 80.0 //Cell height + whitespace
}
cell.cellLabel.text = data[indexPath.row]
return cell
}

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With