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:
fatal error: unexpectedly found nil while unwrapping an Optional value
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
. Try to check if you have initialised your optionals or not before using them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.