我创建了一个自定义单元格并声明了文本字段并使其不可编辑
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)时,我试图让它在这里可以编辑。
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
任何人都可以为此展示一些示例代码吗?
最佳答案
您似乎未初始化您的一些可选值。因此在解包时,您得到的是nil
。在使用它们之前,请尝试检查您是否已经初始化了您的选项。
关于ios - 如何在更改 View 期间使 UITextField 不可编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38655978/