4

I'm loading items from a web service to UITableView in an iOS application. The problem here is that as soon as the data gets loaded, the number of rows that are visible at top without scroll gets invisible. The page gets blank. If i scroll down, the images below gets loaded perfectly. On again scrolling up the top images also gets loaded properly.

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

}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aqib Bangash
  • 963
  • 1
  • 8
  • 22

1 Answers1

1

try;

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

    return cell
}

Don't forget to register your cell.

Shoaib
  • 2,286
  • 1
  • 19
  • 27
  • That was a typing mistake. It is returning the cell properly, but still the same problem. I hope you have seen the screenshots. – Aqib Bangash Sep 16 '15 at 06:00