У меня есть UITableView и внутри UITableViewCell есть 5 текстовых полей. Мне нужно назначить UITextFieldDelegate и вы хотите создать пограничную линию на textField. Я вызываю свою функцию createBorderLine из cellForRowAtIndexPath, но она бросает ошибку (фатальная ошибка: неожиданно найденный nil при развертывании необязательного значения).Как получить границу на textField от cellForRowAtIndexPath?
Ниже мой код:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "EditProductCell"
var editProductCell = tableView.dequeueReusableCell(withIdentifier: identifier) as? EditProductCell
if(editProductCell == nil)
{
let nib:Array = Bundle.main.loadNibNamed("EditProductCell", owner: self, options: nil)!
editProductCell = nib[0] as? EditProductCell
//Call Create Border Line function.
self.createBorderLine()
}
}
И вот моя createBorderLine функция:
func createBorderLine()
{
let index : NSIndexPath = NSIndexPath(row: 0, section: 0)
let tCell : EditProductCell = self.tableView.cellForRow(at: index as IndexPath) as! EditProductCell
tCell.InvoiceDate.delegate = self
tCell.InvoiceNumber.delegate = self
tCell.modelNumber.delegate = self
tCell.productName.delegate = self
tCell.serialNumber.delegate = self
tCell.viewWarrentyDate.isHidden = true
setBottomBorder(textField: tCell.InvoiceDate, width: 0.8,color : UIColor.lightGray)
setBottomBorder(textField: tCell.InvoiceNumber, width: 0.8,color : UIColor.lightGray)
setBottomBorder(textField: tCell.modelNumber, width: 0.8,color : UIColor.lightGray)
setBottomBorder(textField: tCell.productName, width: 0.4,color : UIColor.lightGray)
setBottomBorder(textField: tCell.serialNumber, width: 0.4,color : UIColor.lightGray)
}
Что я могу сделать? Почему он дает ошибку?
Почему вы создаете 'let index: NSIndexPath = NSIndexPath (строка: 0, раздел: 0)'? Вы можете просто передать объект ячейки createBorderLine –
OK На самом деле я немного путаюсь в TableViewConcepts. Основы, которые я знаю. Anyways Спасибо. – kishor0011