在swift中创建自定义tableview单元格 [英] creating custom tableview cells in swift

查看:178
本文介绍了在swift中创建自定义tableview单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义单元格类与几个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
    }

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

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.

这篇关于在swift中创建自定义tableview单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆