1
votes

My cell is either holding collegename or username but it is not holding both values even though i have textlabels on my cell in the storyboard override init(style: UITableViewStyle, className: String!) { super.init(style: style, className: className) }

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    // Configure the PFQueryTableView
    self.parseClassName = "_User"
    self.textKey = "username"
    self.pullToRefreshEnabled = true
    self.paginationEnabled = false
}

override func queryForTable() -> PFQuery {
    var query = PFQuery(className: "_User")
    query.orderByAscending("username")
    return query
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
    let cellIdentifier = "cell"

    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? PFTableViewCell
    if cell == nil {
        cell = PFTableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
    }
    if let usernametable = object?["username"] as? String {
        cell?.textLabel?.text = usernametable
    }
    if let collegename = object?["collegename"] as? String {
       cell?.textLabel?.text = collegename
    }

    return cell
}
1
You are setting cell?.textLabel?.text = usernametable and then overriding the label text cell?.textLabel?.text = collegename. Can you show your PFTableViewCell code? - alephao
I don't have any code on the cell other than declaring the text labels what do I need to add to it for it to work? - Haasith Sanka
You should use the declared UILabels var instead of cell?.textLabel - alephao
you're welcome, I wrote it as the answer. - alephao

1 Answers

0
votes

You should use the declared UILabels var instead of cell?.textLabel

In your custom cell you probably have something like

@IBOutlet weak var usernameLabel: UILabel!
@IBOutlet weak var collegeLabel: UILabel!

So instead of using

if let usernametable = object?["username"] as? String {
    cell?.usernameLabel.text = usernametable
}
if let collegename = object?["collegename"] as? String {
   cell?.textLabel?.text = collegename
}

you should use your custom cell's UILabels

if let usernametable = object?["username"] as? String {
    cell?.usernameLabel.text = usernametable
}

if let collegename = object?["collegename"] as? String {
   cell?.collegeLabel.text = collegename
}