Ich habe eine UITableView und innerhalb von UITableViewCell gibt es 5 TextFields. Ich muss UITextFieldDelegate zuweisen und Grenzlinie auf TextField erstellen. Ich rufe meine Funktion createBorderLine von cellForRowAtIndexPath auf, aber es wirft einen Fehler auf (schwerwiegender Fehler: unerwartet gefundene Null beim Entpacken eines optionalen Werts).Wie erhalten Sie eine Grenzlinie für textField von cellForRowAtIndexPath?
Unten ist mein Code:
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()
}
}
Und hier ist meine createBorderLine Funktion:
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)
}
Was kann ich tun? Warum gibt es einen Fehler?
Warum erstellen Sie 'let index: NSIndexPath = NSIndexPath (row: 0, section: 0)'? Sie können das Zellobjekt einfach an createBorderLine übergeben –
OK Eigentlich bin ich in TableViewConcepts etwas verwirrt. Grundlagen, die ich kenne. Wie auch immer, danke. – kishor0011