【问题标题】:PFTableViewCell init with CoderPFTableViewCell 使用 Coder 初始化
【发布时间】:2014-07-17 00:28:32
【问题描述】:

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

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

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

【问题讨论】:

标签: swift parse-platform


【解决方案1】:

这不是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. 调用超类初始化器
  3. 自定义任何继承的属性并调用实例方法

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

【讨论】:

  • 我有那个初始化器,但它从来没有从类中调用过。 var cell : PhotoCell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as PhotoCell! if cell == nil { cell = PhotoCell(style: .Default, reuseIdentifier: CellIdentifier) }
【解决方案2】:

这最终成为 Xcode 测试版错误。随着 Xcode6-Beta6 的发布,初始化代码被正确调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多