Я хочу добавить табличное представление в мой файл xib, но я получил ошибку.Мой контроллер -
class ViewController: UIViewControllerUITextViewDelegate,UITableViewDataSource,UITableViewDelegate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "Cell"
var cell:UITableViewCell? = yerImleriView.tableView.dequeueReusableCell(withIdentifier: identifier)
if cell == nil {
_ = YerImleri().loadNib() as UIView
tableView.register(UINib(nibName: "YerImleri", bundle: nil), forCellReuseIdentifier: identifier)
cell = yerImleriView.tableView.dequeueReusableCell(withIdentifier: identifier)
cell?.textLabel?.textColor = UIColorFromRGB(rgbValue: 0xEFEFEF)
cell?.textLabel?.text = items[indexPath.row]
cell?.backgroundColor = UIColorFromRGB(rgbValue: 0x3A4858)
cell?.textLabel?.font = UIFont (name: "Proxima Nova", size: 16)
}
return cell!
}
var items: [String] = ["Katmanlar", "Yer Imleri", "GPS Cihazlari", "Kategorik Arama","Cevrimdisi Haritalar"]
override func viewDidLoad() {
super.viewDidLoad()
yerImleriView.tableView.delegate = self
yerImleriView.tableView.dataSource = self
}
}
, а мой Xib-файл -
class YerImleri: UIView{
@IBOutlet var contentView: UIView!
@IBOutlet weak var tableView: UITableView!
override init(frame: CGRect){
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit(){
Bundle.main.loadNibNamed("YerImleri", owner:self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
}
, ошибка:
*** Завершение работы приложения из-за необработанного исключения «NSUnknownKeyException», причина: '[setValue: forUndefinedKey:]: этот класс не соответствует значению ключа, соответствующему кодированию для ключа contentView.'