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.
这篇关于快速创建自定义表格视图单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:快速创建自定义表格视图单元格


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01