ios - 如何在更改 View 期间使 UITextField 不可编辑?

标签 ios swift uitableview

我创建了一个自定义单元格并声明了文本字段并使其不可编辑

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/

相关文章:

iphone - 核心图 - 图形的起点在 (0,0)

ios - 为什么当我从我转至的 View Controller 返回时,我的 UITableView 的格式完全出错?

iphone - 在 UITableView 样式中自定义 selectedBackgroundView 出站分组

ios - 准备 segue NSString 变成 NSObject?

ios - 可变数组 iOS 中的最大元素

swift - 如何在 Swift 中使用 "Extended String Delimiters"?

swift - user_friends 的应用程序不断被拒绝 - Facebook

python - AWS IoT 设备未收到 iOS 应用程序发布的消息

objective-c - 如何在表格中插入行?

ios - 使用相同图像绘制缓慢