快速创建自定义表格视图单元格

creating custom tableview cells in swift(快速创建自定义表格视图单元格)

本文介绍了快速创建自定义表格视图单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有几个 IBOutlets 的自定义单元格类.我已将课程添加到情节提要中.我已经连接了我所有的插座.我的 cellForRowAtIndexPath 函数如下所示:

I have a custom cell class with a couple of IBOutlets. I have added the class to the storyboard. I have connected all my outlets. my cellForRowAtIndexPath function looks like this:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SwipeableCell

        cell.mainTextLabel.text = self.venueService.mainCategoriesArray()[indexPath.row]

        return cell
    }

这是我的自定义单元格类:

Here is my custom cell class:

class SwipeableCell: UITableViewCell {
    @IBOutlet var option1: UIButton
    @IBOutlet var option2: UIButton
    @IBOutlet var topLayerView : UIView
    @IBOutlet var mainTextLabel : UILabel
    @IBOutlet var categoryIcon : UIImageView

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


    }
}

当我运行应用程序时,我的所有单元格都是空的.我已注销 self.venueService.mainCategoriesArray() 并且它包含所有正确的字符串.我也尝试过放置一个与标签相等的实际字符串,这会产生相同的结果.

When I run the app, all my cell are empty. I have logged out self.venueService.mainCategoriesArray() and it contains all the correct strings. I have also tried putting an actual string equal to the label, and that produces the same result.

我错过了什么?任何帮助表示赞赏.

What am I missing? Any help is appreciated.

推荐答案

感谢所有不同的建议,但我终于想通了.自定义类已正确设置.我需要做的就是在故事板中选择自定义类:删除它,然后再次选择它.这没有多大意义,但这最终对我有用.

Thanks for all the different suggestions, but I finally figured it out. The custom class was set up correctly. All I needed to do, was in the storyboard where I choose the custom class: remove it, and select it again. It doesn't make much sense, but that ended up working for me.

这篇关于快速创建自定义表格视图单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:快速创建自定义表格视图单元格

基础教程推荐