2016-07-29 73 views
0

我創建了一個自定義單元格和申報文本字段,並使其不可編輯如何在更改視圖時使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

任何人都可以證明這一些示例代碼?

+0

嗨,大家好,我到目前爲止沒有得到任何解釋 – anand

回答

1

看來你有沒有初始化你的一些optionals.So同時展開,你得到nil。在使用它們之前,嘗試檢查是否初始化了您的選擇權。

+0

如何在viewcontoller中使用uitableviewcell textfield。 – anand

+0

請發佈新的問題,提供更多的細節和代碼,你到目前爲止嘗試過。 –

+0

其實我不能發表新的問題 – anand

相關問題