【问题标题】:Weird issue with UITableView swift 2UITableView swift 2 的奇怪问题
【发布时间】:2015-12-16 10:21:32
【问题描述】:

我目前遇到了 UITableView 的问题。

我从 json 文件中获取一些数据并将它们放入表格视图中,但表格视图有一个奇怪的反应。 当我打开应用程序时,它在单元格中没有任何内容,当我进一步向下然后回到顶部时,它会出现应该出现在单元格内的内容。 如果我下去,它会使单元格内的文本消失。

代码

in ViewDidLoad



        let nib = UINib(nibName: "homeTableViewCell", bundle: nil)
        // Register the nib for reusing within the tableview with your reuseidentifier
        self.activitiesTable.registerNib(nib, forCellReuseIdentifier: "homeCell")

        self.activitiesTable.delegate = self
        self.activitiesTable.dataSource = self

    }


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath) as! homeTableViewCell
        cell.lblContentHomeCell.text = "test"
        return cell
    }

这是模拟器的截图。

即使我在每个单元格中正常写“测试”仍然有同样的问题。 单元格是自定义单元格。 有没有人遇到同样的问题并找到了解决方案?非常感谢您的帮助。

【问题讨论】:

    标签: uitableview swift2 ios9


    【解决方案1】:

    我的第一个应用程序也遇到了类似的问题。看来您必须定义每个单元格的高度。您可以获取单元格的高度并将其返回,也可以使用标准值,如下所示: (在您的表视图代表添加这个)

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    
            return 100.0;
    
        }
    

    【讨论】:

    • 非常感谢!完美运行,希望在iOS开发中看到更多的希腊人!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多