How to stop UITableView from returning to top cell after popover

后端 未结 4 1364
春和景丽
春和景丽 2021-01-24 13:47

I have a tableView full of images. When a user taps on an image (within the cell), a viewController with a larger zoomable version of the image is called with a popover segue. W

4条回答
  •  青春惊慌失措
    2021-01-24 14:14

    most probably the reason for this behavior is that you are calling table reload some where between opening and closing the popover view (probably inside one or more of these methods like viewDidAppear, viewWillAppear etc). If you can simply remove it then it wont be scrolling to top.

    or you can keep the content offset just before opening popover view then set the offset after closing it,

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        tableView.contentOffset = offset
    }
    
    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        offset = tableView.contentOffset
    }
    

提交回复
热议问题