Top rows disappear from UITableView when reloadData () until they scroll up / down

I am loading items from a web service into a UITableView in an iOS app. The problem here is that as soon as the data is loaded, the number of lines that are visible from above without scrolling becomes invisible. The page is blank. If I scroll down, the images below load fine. When scrolling up again, images also load correctly.

Detailed screenshot link: https://www.dropbox.com/sh/nfxcgw2ple8g4mt/AAAOTswWDEN-s2-dAbJ1bHu7a?dl=0

class FirstViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{

   override func viewDidLoad() {
        super.viewDidLoad()[1]

//        self.client = xxxxxxxxxxxx;

//
//   fetching from server logic query
//
//             
    query.readWithCompletion({ (result , error) -> Void in

            if (error == nil)
            {
                self.activityIndicatorView.hidden = true // loading indicator 
                self.allResults = result.items
                    println( self.allResults!.count )
                self.tableView.hidden = false
                self.tableView.reloadData()
            }
            else{
                println(error.localizedDescription) // error
            }

        })

    }

   func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        if (allResults != nil) {  return self.allResults.count }
        else {  return 0 }
    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
    { return 200 }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
         var cell: CellClass  = self.tableView.dequeueReusableCellWithIdentifier("item") as! CellClass

        return cell //typo

}
+4
source share
1 answer

to try

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell {
    let cell:CellClass   = tableView.dequeueReusableCellWithIdentifier("item", forIndexPath: indexPath) as! CellClass

    return cell
}

Remember to register your cell.

+1

Source: https://habr.com/ru/post/1607523/


All Articles