**For ios 11.2.* **
tableView.rowHeight = UITableViewAutomaticDimension in viewDidLoad()
add estimatedHeightForRowAt
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0{
return firstCellHeight()
}
else{
return UITableViewAutomaticDimension
}
}
firstCellHeight
is my First Cell Height
func firstCellHeight() -> CGFloat{
if UIDevice.Display.typeIsLike == UIDevice.DisplayType.ipad{
return 400
}else if UIDevice.Display.typeIsLike == UIDevice.DisplayType.iphone7plus{
return 230
}else if UIDevice.Display.typeIsLike == UIDevice.DisplayType.iphoneX{
return 200
}else{
return 180
}
}
and Don't use: reloadRows
let indexPath = IndexPath(item: 1, section: 0)
tableView.reloadRows(at: [indexPath], with: .none)
Instead use reloadData
i.e tableView.reloadData()
And Finally Where your Action required, Use bellow code:
let indexPath0 = IndexPath(item: 0, section: 0)
if !((tableView.indexPathsForVisibleRows?.contains(indexPath0))!) {
print("Not Visible")
self.tableView.setContentOffset(CGPoint(x:0, y:firstCellHeight() ), animated: false)
}