【问题标题】:Custom UITableViewCell overlapping objects自定义 UITableViewCell 重叠对象
【发布时间】:2014-09-04 07:03:33
【问题描述】:

我有一个自定义的 TableViewCell,其中包含以下代码:

import Foundation
import UIKit

class MatchCell : UITableViewCell {

    @IBOutlet var blueTeamLogoImageView: UIView
    @IBOutlet var blueTeamNameShort: UILabel
    @IBOutlet var blueTeamScore: UILabel
    @IBOutlet var blueTeamStats: UILabel
    @IBOutlet var blueTeamWinIndicator: UIView


    @IBOutlet var redTeamLogoImageView: UIImageView
    @IBOutlet var redTeamNameShort: UILabel
    @IBOutlet var redTeamScore: UILabel
    @IBOutlet var redTeamStats: UILabel
    @IBOutlet var redTeamWinIndicator: UIView

    init(style: UITableViewCellStyle, reuseIdentifier: String!) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
}

现在我尝试将我的 MatchCell 添加到我的 !GROUPED! (不知道它是否有任何区别) UITableView。我已经实现了:

func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String func numberOfSectionsInTableView(tableView: UITableView!) -> Int

并添加:tableView.dataSource = self 他们都返回了正确的值,已经检查过了。

现在当我运行我的应用程序时......它看起来像这样:http://www1.xup.to/exec/ximg.php?fid=14474271

这是我的 cellForRowAtIndexPath:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) ->     UITableViewCell! {
    if self.lcsWeek {

        let cell: MatchCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MatchCell

        var currentDay: Day = self.lcsWeek!.Days[self.lcsWeek!.getDayById(indexPath.section)]!
        var currentMatch: Match = currentDay.matches[indexPath.row]

        cell.blueTeamNameShort.text = currentMatch.blueTeamAcronym
        cell.redTeamNameShort.text = currentMatch.redTeamAcronym

        return cell
    }
    else {
        return nil
    }
}

应该是这样的:http://www1.xup.to/exec/ximg.php?fid=19982127

我认为问题出在 cellForRowAtIndexPath 函数的某个地方...希望有人可以帮助我

【问题讨论】:

    标签: ios uitableview swift


    【解决方案1】:

    你应该实现这个:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    

    您的表格没有信息,这些单元格应该有多大。

    【讨论】:

    • 它现在就像一个魅力。太感谢了! tableView.delegate = self and func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat 成功了:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2016-05-23
    • 1970-01-01
    相关资源
    最近更新 更多