2015-03-08 53 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?) { 
相關問題