ios - 如何通过单击 UITableViewController 中的自定义单元格来禁用 segue 而不禁用此单元格中的 textField 编辑

标签 ios swift

我有带有 textfild 的自定义单元格。 对于某些单元格,我需要通过单击禁用 segue 并启用文本字段进行编辑。我试试看:

    if indexPath.row<tests.count{
       cell.themeTextField?.text = test.name
       cell.themeTextField.enabled=false
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryType.None
        cell.selectionStyle = UITableViewCellSelectionStyle.None;
        cell.userInteractionEnabled = false;   
    }

Segue 被禁用,但我无法在 textField 中输入文本

最佳答案

尝试替代,

从 tableCell 中删除那个 segue 并从 UITableViewController 创建一个新的(将它从对象导航器而不是 Storyboard 中拖动)到下一个 Controller - 并给它一个名称(例如:DidSelectCellSegue).

然后在 didSelectRowAtIndexPath: 委托(delegate)方法中,以编程方式和有条件地执行 segue。

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

    if conditionForPerformingSegueIsSatisfied {
        self.performSegueWithIdentifier("DidSelectCellSegue", sender: self)
    }
}

并将cellForRow代码更改为

if indexPath.row<tests.count{
   cell.themeTextField?.text = test.name
   cell.themeTextField.enabled=false
}
else {
    cell.accessoryType = UITableViewCellAccessoryType.None
    cell.selectionStyle = UITableViewCellSelectionStyle.None;
    cell.themeTextField.enabled = true;   
}

关于ios - 如何通过单击 UITableViewController 中的自定义单元格来禁用 segue 而不禁用此单元格中的 textField 编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27682976/

相关文章:

ios - 获取赢-输计数器以保存在用户默认的 swift 中

ios - 使用 UIImage : NSData is not nil, 进行 Base64 转换,但 UIImage 为 nil

ios - 如何获取位置坐标以在另一个类中更新?

iphone - 根据设备类型选择不同的 Storyboard

swift - 如何将 Button 的 .setTitle 参数放入 UserDefaults 和 viewDidLoad 中

ios - 转换在 iOS swift 中没有正确发生?

ios - 以编程方式自动布局不起作用

ios - 如何在 UIImageview 中绘制椭圆形

ios - 这个 Xcode 项目文件夹层次结构最可能的设计模式是什么?

ios - Swift iOS - 当作为 subview Controller 添加到另一个 View Controller 时,是否应该在 subview Controller 中调用 Deinit?