james james - 5 months ago 12
Swift Question

tableView shows prototype cell and custom cell

I have a tableView that once loaded data correctly in the cells (it was a basic tableView with the default prototype cell). However, once I added a custom cell class I get a strange issue. My tableView now loads the actual prototype cell (what I customized in the storyboard) in addition to the data from the data source.

Here's an image of what I'm seeing. The first row is the prototype cell. It's identical to what I see in the storyboard view. The second row is the legit data that is being loaded.

enter image description here

Here's the cellForRowAtIndexPath. Not sure what went wrong:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("AlertCell", forIndexPath: indexPath) as? AlertCell

let inviteDict = invites[indexPath.row].value as! [String : AnyObject]
if let userID = inviteDict["invitedBy"] as? String {

let name = getUser(userID, closure: { (name) in
cell!.alertText!.text = "\(name)" + " " + "would like to be your friend"
})
}
return cell!
}


Any ideas?

Thanks!

Answer

Check your data if its correct. And make sure your numberOfRowsInSection return the data count as expected.

Comments