UITableView가 있고 UITableViewCell 안에 5 개의 textField가 있습니다. UITextFieldDelegate를 할당하고 textField에 테두리를 만들고 싶습니다. cellForRowAtIndexPath에서 내 함수 createBorderLine을 호출하고 있지만 오류가 발생합니다 (치명적인 오류 : Optional 값을 풀 때 예기치 않게 nil을 찾았습니다).
아래는 내 코드입니다.
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)
}
어떡해? 왜 오류가 발생합니까?
createBorderLine에서 매번 행 0 및 섹션 0에 대한 인덱스 경로를 만드는 이유는 무엇입니까? createBorderLine에서 셀 참조를 전달하기 만하면됩니다.
self.createBorderLine(editProductCell)
그리고 createBorderLine
기능
func createBorderLine(tCell: 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)
}
대신 작성하는 createBorderLine
컨트롤러 클래스에서 당신은 놓아야 createBorderLine
에서 EditProductCell
클래스입니다. EditProductCell 객체 ref를 통해 직접 호출합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다