Я пытаюсь создать настраиваемую ячейку табличного представления.
Если я сделаю это:
class TableViewCell: UITableViewCell {
@IBOutlet weak var cellBackgroundImage : UIImageView!
}
И
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
cell.cellBackgroundImage.backgroundColor = UIColor.white
cell.cellBackgroundImage.layer.masksToBounds = false
cell.cellBackgroundImage.layer.cornerRadius = 5
let event = self.fetchedResultsController.object(at: indexPath)
self.configureCell(cell, withEvent: event)
return cell
}
Я получаю белый округлый фон клетки. Легко. И я могу использовать оригинал cell.textLabel.text
.
Совершенная.
Но, если я хочу сделать что-то более сложное:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? TableViewCell
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Cell") as? TableViewCell
cell?.cellBackgroundImage.backgroundColor = UIColor.white
cell?.cellBackgroundImage.layer.masksToBounds = false
cell?.cellBackgroundImage.layer.cornerRadius = 5
self.configureCell(cell!, withObject: object)
}
И в то же время, чтобы использовать исходные свойства табличного представления как UITableViewCellStyle.subtitle
и cell.accessoryView
, приложение вылетает или показывает неправильный вывод.
ЭТО ОЗНАЧАЕТ, ЧТО Я ДОЛЖЕН ИСПОЛЬЗОВАТЬ ПОЛНУЮ ТАМОЖЕННУЮ ЭЛЕМЕНТУ С БОЛЕЕ ВЫХОДАМИ ДЛЯ ЗАМЕНЫ ОРИГИНАЛЬНЫХ ЭЛЕМЕНТОВ КАК UITableViewCellStyle.subtitle и cell.accessoryView ???
Я скажу это по-другому:
Можно ли использовать настраиваемую ячейку табличного представления только для одной цели (например, округленный фон) и использовать оригинальные элементы, такие как стиль субтитров и вспомогательное представление?
В позитивном случае как?