我想將多個子類添加到UITableView中。問題是,它不斷給我下面的錯誤:UITableViewCOntroller中的swift多個單元子類
Type UITableVieCell does not conform to protocol NilLiteralConvertible
的cellForRowAtIndexPath
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = self.section1[indexPath.row]
cell.accessoryType = .DisclosureIndicator
return cell
} else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCellWithIdentifier("SwitchViewCell", forIndexPath: indexPath) as SwitchViewCell
cell.cellLabel?.text = self.section2[indexPath.row]
return cell
}
return nil
}
該解決方案生成和Xcode 6警告:'不可變值是默認初始化,無法再changed'。此外,創建一個隱式解包的可選初始化爲nil,希望永遠不會調用,以便爲需要返回非可選'UITableViewCell'的方法提供錯誤消息,這看起來就像錯誤的代碼設計。 – 2014-10-01 14:47:43
他也可以使用,而不是「} else if indexPath.section == 1 {」only} else { - 返回一個單元格。我剛剛出現了什麼問題。或者使用開關/大小寫,並在默認情況下返回空單元格。 – derdida 2014-10-01 14:50:37