gpt4 book ai didi

swift - 使用 Coder 初始化 PFTableViewCell

转载 作者:行者123 更新时间:2023-11-28 07:17:42 26 4
gpt4 key购买 nike

我有一个继承自 PFTableViewCell 的自定义类。我想使用 Storyboard 来初始化类(class)。我使用“tableView.dequeueReusableCellWithIdentifier”创建它,所以我认为我需要以下初始化程序。

init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
//...custom init code...
}

不幸的是,它不起作用......

Error Message

最佳答案

这不是 PFTableViewCell 的指定初始化器——它继承自 UITableViewCell,它使用:

// Designated initializer.  If the cell can be reused, you must pass in a reuse identifier.  You should use the same reuse identifier for all cells of the same form.  
init(style: UITableViewCellStyle, reuseIdentifier: String!)

在继承的指定初始化器中,您需要按特定顺序进行设置:

  1. 初始化你自己的所有属性
  2. 调用父类(super class)初始化器
  3. 自定义任何继承的属性并调用实例方法

请注意,这与 Objective-C 中的初始化不同,在 Objective-C 中我们在执行任何其他操作之前调用了 self = [super init]

关于swift - 使用 Coder 初始化 PFTableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24793041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com