iosswiftuitableviewios11uitableviewrowaction

UITableView Reload Rows unnaturally jerking the TableView in iOS 11.2


Strange issue arrived after updating new XCODE 9.2 with iOS 11.2, by calling

let indexPath = IndexPath(item: 0, section: 1)
self.tableViewHome.reloadRows(at: [indexPath], with: .none)

It causes unnecessary jerking the whole TableView, Prior it was very fine with these code.

GIF Image for iOS 11.2

enter image description here

GIF Image for iOS 11.1

enter image description here

How to stop this Jerking, I have to reload only one cell in the tableview among two cells.

Any help will be appreciated.

Thanks


Solution

  • **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)
            }