First cell wrong size

62 views Asked by At

I need to get the first cell in my tableView to be a different size from the rest. The rest of my cells are all under the class CustomPFTableViewCell, but the first one is a different cell so its under the class FirstPFTableViewCell, both of which extend from the class PFTableViewCell. Right now, I just used an if depending on the indexPath.row for whether or not the cell was the first cell. When its not it will load data for the cell from Parse.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
    if(indexPath.row >= 1){
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomPFTableViewCell!

    print("Loading Parse Database Files...")
    // Extract values from the PFObject to display in the table cell
    if let name = object?["Name"] as? String {
        cell?.nameTextLabel?.text = name
        print("Loading " + name)
    }
    if let author = object?["authorName"] as? String {
        cell?.authorTextLabel?.text = author
    }
    if let likes = object?["Likes"] as? Int {
        let stringVal = String(likes)
        cell?.numLikes.text = stringVal
    }
    if let descrip = object?["Description"] as? String {
        cell?.descriptionHolder = descrip
    }
    let initialThumbnail = UIImage(named: "Unloaded")
    cell.customFlag.image = initialThumbnail
    if let thumbnail = object?["imageCover"] as? PFFile {
        cell.customFlag.file = thumbnail
        cell.customFlag.loadInBackground()
    }
        return cell
    }

    print("Finished loading!")



    let cell = tableView.dequeueReusableCellWithIdentifier("firstCell") as! PFTableViewCell
    return cell


}

The end is empty because I'm not sure how to go about changing the one/first cell's size. (In the Interface Builder its set to 60). I guess the most important part in solving this is this:

    let cell = tableView.dequeueReusableCellWithIdentifier("firstCell") as! PFTableViewCell
    return cell


}
1

There are 1 answers

0
sken3r.MI On BEST ANSWER

In order to play with the size of the cell you have to implement the UITableViewDelegate function

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == 0 {
    return firstCellHeight
} else {
    return customCellHeight
}