2015-03-08 52 views
1

嗨我是IOS编程的新手,并且试图了解下面的错误实际上告诉我以及如何解决它。任何人都可以帮忙吗?错误:在super.init初始化之前使用自己的属性访问'reuseidentifier'

下面添加我的TableViewCell.swift文件中的代码。

import UIKit 

class SweetTableViewCell: UITableViewCell { 

    @IBOutlet var usernameLabel: UILabel! = UILabel() 
    @IBOutlet var timestampLabel: UILabel! = UILabel() 
    @IBOutlet var profileImageView: UIImageView! = UIImageView() 
    @IBOutlet var sweetTextView: UITextView! = UITextView() 

    required init(coder aDecoder: (NSCoder!)) { 
     super.init(coder: aDecoder) 
    } 


    override init(style: UITableViewCellStyle, reuseIdentifier reuseIdenifier: String?) { 
     super.init(style: style, reuseIdentifier: reuseIdentifier) 
     // Initialization code 
    } 
} 
+0

你能解决您的代码格式化,并在你的问题的身体证明你是错误信息接收? – 2015-03-08 19:00:39

回答

1

令人困惑的错误消息,但我相信问题是您的“reuseIdenifier”本地参数名称。

尝试:

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
    super.init(style: style, reuseIdentifier: reuseIdentifier) 
} 

不幸的是,我不能深层链接,但看斯威夫特文档中的外部参数名称部分:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html

它给这个错误的原因是因为你是真的在使用reuseIdentifier时,在init中访问self.reuseIdentifier是因为reuseIdenifier实际上是该范围内的参数(由于本地参数名称)。在自我初始化之前,您无法访问自己的属性。

1

这是一个输入错误,则t丢失:

reuseIdenifier 
     ^^ 

所以在init身体,你实际上指的是实例属性,这就是错误的状态。

但是由于外部和本地名称是一样的,它只是更好,如果你使用#快捷:

override init(style: UITableViewCellStyle, # reuseIdentifier: String?) { 
相关问题