ios - 第一个单元格大小错误

标签 ios swift uitableview parse-platform pftableviewcell

我需要让 tableView 中的第一个单元格与其余单元格的大小不同。我的其余单元格都位于 CustomPFTableViewCell 类下,但第一个单元格是不同的单元格,因此它位于 FirstPFTableViewCell 类下,这两个单元格都从 PFTableViewCell 类扩展。现在,我只是根据 indexPath.row 使用 if 来判断单元格是否是第一个单元格。如果不是,它将从 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


}

末尾是空的,因为我不确定如何更改第一个单元格的大小。 (在 Interface Builder 中将其设置为 60)。我想解决这个问题最重要的部分是:

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


}

最佳答案

为了调整单元格的大小,您必须实现 UITableViewDelegate 函数

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

关于ios - 第一个单元格大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35367188/

相关文章:

ios - 在 AFNetworking 中替代 JSONRepresentation

ios - UNUserNotification 永远不会在安排在以后的日期出现

ios - 设置标签的文本会导致堆栈 View 布局问题

iphone - 是否可以向 UITableView 添加边框样式? (不是边框颜色/边框宽度)

ios - 使用 Simple TableView Swift 进行单元格构造的奇怪行为

iphone - UITableView 自定义部分标题显示在单元格下方

ios - 使用UIImage放大UIView而不影响UIImage的分辨率

ios - UI 导航栏标题和右栏按钮显示在我拥有的所有 View Controller 中

swift - 如何使用默认样式初始化 tableViewCell?

ios - UIAlertController 的解雇