Tôi có một UITableViewCel tùy chỉnh (không có gì ưa thích) hoạt động hoàn hảo trên Xcode 6.0. Khi tôi cố gắng biên dịch nó với Xcode 6.1 trình biên dịch cho thấy lỗi sau:Trình khởi tạo có sẵn trong Xcode 6.1
A non-failable initializer cannot chain to failable initializer 'init(style:reuseIdentifier:)' written with 'init?'
Đây là mã của tế bào:
class MainTableViewCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.setup()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
func setup() {<...>}
}
Là một giải pháp trình biên dịch đề xuất Propagate the failure with 'init?'
:
override init?(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.setup()
}
Tôi hơi bối rối. Có thể xây dựng (non)failable initialiser
là gì và cách sử dụng và ghi đè nó?
Bạn đang nói về Xcode 6.0 và 6.1? –
Vâng, bạn nói đúng, gần như là một đêm mà tôi đang ở và tôi hơi buồn ngủ. :) –
Ngoài ra, như tôi đã hiểu, bạn nên đặt lệnh gọi super.init ở cuối hàm. Tôi đoán nếu bạn không có bất kỳ tài sản, sau đó nó không quan trọng. –