[英]How to make UITextField uneditable during changing the view?
I created a custom cell and declare text field and make it non-editable 我创建了一个自定义单元格并声明了文本字段,并使它不可编辑
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")
}
}
When I come to the another class, I am trying to make it editable here. 当我参加另一堂课时,我正在尝试使其在此处可编辑。
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()
}
}
}
When I am calling my method SuppliersCutomTableViewCell().edit()
it's showing the error: 当我调用我的方法
SuppliersCutomTableViewCell().edit()
,显示错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
致命错误:解开Optional值时意外发现nil
Can anyone show some sample code for this? 谁能为此显示一些示例代码?
It seems that you have not initialised some of your optionals.So while unwrapping , you are getting nil
. 似乎还没有初始化一些可选参数。因此,在展开时,您将得到
nil
。 Try to check if you have initialised your optionals or not before using them. 在使用可选选项之前,请尝试检查它们是否已初始化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.