私はUITableViewを持っていて、内部には5つのtextFieldがあります。 私はUITextFieldDelegateを割り当てて、textFieldに境界線を作成します。私はcellForRowAtIndexPathから関数createBorderLineを呼び出していますが、それはエラーを投げています(致命的なエラー:予期せず、オプション値をアンラッピングしている間にnilが見つかりました)。以下はcellForRowAtIndexPathからtextFieldの境界線を取得するにはどうすればよいですか?
は私のコードです:
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で混乱しています。私が知っている基本は です。とにかくありがとうございます。 – kishor0011