Tôi đang cố gắng thêm nhiều lớp con vào một UITableView. Vấn đề là nó giữ cho tôi lỗi sau:nhiều lớp con nhanh trong UITableViewCOntroller
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
}
Giải pháp này tạo ra một cảnh báo với Xcode 6: 'giá trị bất di bất dịch là mặc định khởi tạo và không bao giờ có thể được changed'. Hơn nữa, việc tạo ra một tùy chọn không được khai báo hoàn toàn được khởi tạo với nil và hy vọng không bao giờ được gọi để im lặng một thông báo lỗi cho một phương thức yêu cầu trả về một 'UITableViewCell' không bắt buộc có vẻ như thiết kế mã lỗi. –
Ông cũng có thể sử dụng thay vì "} else nếu indexPath.section == 1 {" only} else {- để trả về một ô. Tôi chỉ cho thấy vấn đề là gì. Hoặc sử dụng một Switch/Case và trả về một ô trống theo mặc định. – derdida