Próbuję dodać wiele podklas do UITableView. Problemem jest to, że utrzymanie daje mi następujący błąd:Swift wielu podklas komórek w 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
}
Rozwiązanie to generuje ostrzeżenie z Xcode 6: 'Niezmienne jest wartość domyślna zainicjowany i nigdy nie może być changed'. Co więcej, tworzenie nieopakowanego opcjonalnie opcji inicjalizowanej zerą i która, mam nadzieję, nigdy nie jest wywoływana, aby wyciszyć komunikat o błędzie dla metody, która wymaga zwrócenia nie-opcjonalnej 'UITableViewCell', wygląda na zły projekt kodu. –
Może również użyć zamiast "} else if indexPath.section == 1 {" only} else {- aby zwrócić komórkę. Właśnie pokazałem, na czym polega problem. Lub użyj przełącznika/obudowy i zwróć pustą komórkę domyślnie. – derdida