我創建了一個自定義單元格和申報文本字段,並使其不可編輯如何在更改視圖時使UITextField不可編輯?
class SuppliersCutomTableViewCell: UITableViewCell {
/*Input*/
@IBOutlet weak var compNameField:UITextField!
@IBOutlet weak var companyTypeField: UITextField!
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var numberField: UITextField!
@IBOutlet weak var addressField: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
compNameField.userInteractionEnabled = true
compNameField.enabled = false
func edit() {
compNameField.userInteractionEnabled = true
compNameField.enabled=true
print("edit")
}
}
當我來到了另一個類,我試圖使它可編輯在這裏。
class SuppliersViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{
let edit = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit"){(UITableViewRowAction,NSIndexPath) -> Void in
if indexPath.row == 0{
SuppliersCutomTableViewCell().edit()
}
}
}
當我打電話給我的方法SuppliersCutomTableViewCell().edit()
它顯示的錯誤:
fatal error: unexpectedly found nil while unwrapping an Optional value
任何人都可以證明這一些示例代碼?
嗨,大家好,我到目前爲止沒有得到任何解釋 – anand