[英]How to make UITextField uneditable during changing the view?
我創建了一個自定義單元格並聲明了文本字段,並使它不可編輯
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()
,顯示錯誤:
致命錯誤:解開Optional值時意外發現nil
誰能為此顯示一些示例代碼?
似乎還沒有初始化一些可選參數。因此,在展開時,您將得到nil
。 在使用可選選項之前,請嘗試檢查它們是否已初始化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.