Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 禁用superview用户交互时的子视图用户交互_Ios_Iphone_Swift_Cocoa Touch - Fatal编程技术网

Ios 禁用superview用户交互时的子视图用户交互

Ios 禁用superview用户交互时的子视图用户交互,ios,iphone,swift,cocoa-touch,Ios,Iphone,Swift,Cocoa Touch,我希望保持子视图(在本例中为UITextFields)仍处于活动状态(以通常方式可编辑,即点击文本字段并显示键盘),同时将UITableViewCell的userInteractionEnabled父视图设置为false 进一步解释- 1.存在从xib初始化的UITableViewCell 在这个单元格中,我有三个UIExtFields和一个UIButton 在某些情况下,我需要禁用单元格交互(以避免didSelectRowAtIndexPath)——这部分我没有任何问题 步骤3之后,单元内的所

我希望保持子视图(在本例中为UITextFields)仍处于活动状态(以通常方式可编辑,即点击文本字段并显示键盘),同时将UITableViewCell的userInteractionEnabled父视图设置为false

进一步解释- 1.存在从xib初始化的UITableViewCell

  • 在这个单元格中,我有三个UIExtFields和一个UIButton
  • 在某些情况下,我需要禁用单元格交互(以避免didSelectRowAtIndexPath)——这部分我没有任何问题
  • 步骤3之后,单元内的所有子视图也将被禁用
  • 但我需要在文本字段中输入一些文本,然后点击按钮并执行一些操作
  • 到目前为止我所做的: 1.已使用userInteractionEnabled并为单元格将其设置为false-

    myPersonalInfoExpandedCell.userInteractionEnabled = false
    
    二,。两个文本字段firstNameText和lastNameText,我启用了userInteraction并将其设置为firstNameText成为firstresponder

     (myPersonalInfoExpandedCell as! PersonalInfoExpandedCell).firstNameText.userInteractionEnabled = true
     (myPersonalInfoExpandedCell as! PersonalInfoExpandedCell).lastNameText.userInteractionEnabled = true
     (myPersonalInfoExpandedCell as! PersonalInfoExpandedCell).firstNameText.becomeFirstResponder()
    
    问题是,对于文本字段,
    userInteractionEnabled
    不工作,我怀疑这是因为
    userInteractionEnabled
    对于TableViewCell为false。
    becomeFirstResponder()
    正在为
    firstNameText
    工作,但我需要与单元格内的所有UI元素进行交互


    我们怎么能做到呢?有人可以帮忙吗?

    要禁用单元格选择,请执行willSelectRowAtIndexPath委托方法,并为不想选择的单元格返回nil。您说您希望在某些条件下禁用选择,因此我假设您对要禁用选择的行具有INDExpath。对于这些索引,只需返回nil。请参阅下面的代码

    -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (indexPath == self.MyIndex) //Check for the index path for the cell you want to disable selection for
       return nil;
    else
       return indexPath;
    }
    
    也可以这样做以防止单元格高亮显示

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    这样做,您不必在单元格上设置UserInteractionEnabled:NO。这样,当您点击单元格时,将不会调用didSelectRowAtIndexPath委托方法,并且您的文本字段仍将启用

    编辑

    以下是上述代码的swift版本

    func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
    if (indexPath == self.MyIndex) //Check for the index path for the cell you want to disable selection for
        return nil;
    else
        return indexPath;
    }
    
    
    cell.selectionStyle = .None
    

    要禁用单元格选择,请执行willSelectRowAtIndexPath委托方法,并为不希望选择的单元格返回nil。您说您希望在某些条件下禁用选择,因此我假设您对要禁用选择的行具有INDExpath。对于这些索引,只需返回nil。请参阅下面的代码

    -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (indexPath == self.MyIndex) //Check for the index path for the cell you want to disable selection for
       return nil;
    else
       return indexPath;
    }
    
    也可以这样做以防止单元格高亮显示

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    这样做,您不必在单元格上设置UserInteractionEnabled:NO。这样,当您点击单元格时,将不会调用didSelectRowAtIndexPath委托方法,并且您的文本字段仍将启用

    编辑

    以下是上述代码的swift版本

    func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
    if (indexPath == self.MyIndex) //Check for the index path for the cell you want to disable selection for
        return nil;
    else
        return indexPath;
    }
    
    
    cell.selectionStyle = .None
    

    谢谢你的回答,沙岩!对于我不想选择的单元格,是否返回false?我不明白。你能举个例子吗?@LohithKorupolu我已经编辑了我的答案。看一看。如果您仍然有问题,请随时联系askIt的工作,我可以编辑我的文本字段,但在同一视图中我的UIButton有问题。当我点击该按钮时,我得到一个异常libc++abi.dylib:以NSException类型的未捕获异常终止签出此链接。这很可能是您的IBOutlet有问题。删除所有连接并重新添加是的,我已经看过了。但可能我应该删除连接并重新添加它们。但是对于实际的答案,我接受它:-)谢谢你的回答沙岩!对于我不想选择的单元格,是否返回false?我不明白。你能举个例子吗?@LohithKorupolu我已经编辑了我的答案。看一看。如果您仍然有问题,请随时联系askIt的工作,我可以编辑我的文本字段,但在同一视图中我的UIButton有问题。当我点击该按钮时,我得到一个异常libc++abi.dylib:以NSException类型的未捕获异常终止签出此链接。这很可能是您的IBOutlet有问题。删除所有连接并重新添加是的,我已经看过了。但可能我应该删除连接并重新添加它们。但对于实际答案,我接受它:-)