Konstantinos Natsios
Konstantinos Natsios

Reputation: 2924

Weird issue with UITableView swift 2

I 'm currently having an issue with a UITableView.

I get some data from a json file and throw them in a table view but there is a strange reaction with the table view. When i open the app it has nothing in the cells and when i go further down and then back to the top it appears what it should be appeared inside the cells. And if i go down it dissapears the texts inside the cells.

The code

in ViewDidLoad



        let nib = UINib(nibName: "homeTableViewCell", bundle: nil)
        // Register the nib for reusing within the tableview with your reuseidentifier
        self.activitiesTable.registerNib(nib, forCellReuseIdentifier: "homeCell")

        self.activitiesTable.delegate = self
        self.activitiesTable.dataSource = self

    }


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath) as! homeTableViewCell
        cell.lblContentHomeCell.text = "test"
        return cell
    }

And here are the screenshots from the emulator.

enter image description here enter image description here enter image description here

Even if i write normally "test" in every cell still has the same problem. The cells are custom cells. Does anyone had the same problem and found the solution? Would appreciate your help.

Upvotes: 1

Views: 62

Answers (1)

i had a similar problem with my first app. It seems that you have to define the height of each cell. You can either get cell's height and return it, or use a standar value, like this: (at your table view delegates add this one)

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

        return 100.0;

    }

Upvotes: 2

Related Questions