Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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/5/objective-c/22.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/4/string/5.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 如何在UITableView单元格中为特定部分禁用tableViewCell选择_Ios_Objective C_Iphone_Swift_Uitableview - Fatal编程技术网

Ios 如何在UITableView单元格中为特定部分禁用tableViewCell选择

Ios 如何在UITableView单元格中为特定部分禁用tableViewCell选择,ios,objective-c,iphone,swift,uitableview,Ios,Objective C,Iphone,Swift,Uitableview,我是iOS新手,现在我需要执行与UITableView单元格相关的两个操作,我的单元格中有一个检查图像,单击该图像后,我会得到触摸响应,但如果我点击图像区域以外的任何位置,就会调用didSelectRowAtIndexPath方法 我应该如何实现仅对单元格内的选定区域调用didSelectRowAtIndexPath,而忽略其余区域,或禁用对单元格少数区域的触摸 请在cellForRowAtIndexPath中编写此代码: 如果您添加复选框并取消复选框,则在cellForRowAtIndexPa

我是iOS新手,现在我需要执行与UITableView单元格相关的两个操作,我的单元格中有一个检查图像,单击该图像后,我会得到触摸响应,但如果我点击图像区域以外的任何位置,就会调用didSelectRowAtIndexPath方法

我应该如何实现仅对单元格内的选定区域调用
didSelectRowAtIndexPath
,而忽略其余区域,或禁用对单元格少数区域的触摸

请在cellForRowAtIndexPath中编写此代码:

如果您添加复选框并取消复选框,则在cellForRowAtIndexPath中编写此代码

然后在didselectedrowatinexpath中

编写按钮操作:

根据您的要求更改名称

我希望它能对您有所帮助。

请在cellForRowAtIndexPath中编写以下代码:

如果您添加复选框并取消复选框,则在cellForRowAtIndexPath中编写此代码

然后在didselectedrowatinexpath中

编写按钮操作:

根据您的要求更改名称


我希望它能对您有所帮助。

如果您的检查图像是UIBUtton,请尝试此操作

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.allowsSelection = false;
}

希望它能帮助你

如果你的检查图像是UIBUtton,那么试试这个

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.allowsSelection = false;
}
希望对你有帮助

  • 将tableview选择样式设置为
    UITableViewCellSelectionStyleNone

  • 实现以下任一委托方法,该方法将停止调用
    didselectrowatinexpath

  • 为您的check ImageView设置
    userInteractionEnabled
    ,并实现图像点击的方法(使用
    UIButton
    或带有点击手势的
    UIImageView

    - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
         return NO;
    }
    
  • 希望这有帮助

  • 将tableview选择样式设置为
    UITableViewCellSelectionStyleNone

  • 实现以下任一委托方法,该方法将停止调用
    didselectrowatinexpath

  • 为您的check ImageView设置
    userInteractionEnabled
    ,并实现图像点击的方法(使用
    UIButton
    或带有点击手势的
    UIImageView

    - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
         return NO;
    }
    

  • 希望这有帮助。

    首先将imageview设置为uibutton

    并将
    cellselectionstyle
    设置为无

    在cellForRowIndexPath中:

    在方法中,获取单击按钮行号的标记值,如下所示:

    -(void)CrossClicked:(UIButton *)sender{
    
    int index = sender.tag;
    
    //on basis of index you can perform all task
    
    }
    

    首先将imageview设置为uibutton

    并将
    cellselectionstyle
    设置为无

    在cellForRowIndexPath中:

    在方法中,获取单击按钮行号的标记值,如下所示:

    -(void)CrossClicked:(UIButton *)sender{
    
    int index = sender.tag;
    
    //on basis of index you can perform all task
    
    }
    

    我理解你的问题。您必须覆盖自定义UITableViewCell中的touchsbegind(touchs:Set,withEvent-event:UIEvent?方法

     class CustomTableViewCell: UITableViewCell {
       var isValidTouch: Bool = true
    
       override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    
        if let touch = touches.first {
           let point = touch.locationInView(self.contentView)
           let validTouchPoint = self.contentView.bounds.width - (checkMarkView.bounds.width + 16.0) //Trailing + Leading space
            if point.x < validTouchPoint {
                isValidTouch = true
            } else {
                isValidTouch = false
                //Send tap gesture callback to your viewcontroller
            }
        }
        super.touchesBegan(touches, withEvent: event)
      }
    
    }
    

    我理解你的问题。您必须覆盖自定义UITableViewCell中的touchsbegind(touchs:Set,withEvent-event:UIEvent?方法

     class CustomTableViewCell: UITableViewCell {
       var isValidTouch: Bool = true
    
       override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    
        if let touch = touches.first {
           let point = touch.locationInView(self.contentView)
           let validTouchPoint = self.contentView.bounds.width - (checkMarkView.bounds.width + 16.0) //Trailing + Leading space
            if point.x < validTouchPoint {
                isValidTouch = true
            } else {
                isValidTouch = false
                //Send tap gesture callback to your viewcontroller
            }
        }
        super.touchesBegan(touches, withEvent: event)
      }
    
    }
    

    你能给你的tableviewcell一个屏幕截图吗?带有禁用触摸的区域是否与你参考的图像分开?因此,该单元有3个不同的区域:1)触发didSelectRowAtIndexPath,2)检查图像,3)对触摸没有反应?@dylansturg:是的。。!不是三个,而是两个方面,1。直到检查图像和2。检查图像区域。问题是,如果我只是在调用的图像didSelectRowAtIndexPath方法外轻轻点击,我需要使其可选择。您可以在单元格的特定区域添加点击手势,而不需要实现didSelectRowAtIndexPath方法。我正在使用自定义类来识别图像点击并获得正确的响应。但是正如我上面所说的,如果用户在图像边界外轻轻点击,则会触发DidSelectRowatineXpath方法,因此我需要使该区域不可触摸。您能给出tableviewcell的屏幕截图吗?具有禁用触摸的区域是否与您参考的图像分开?因此,该单元有3个不同的区域:1)触发didSelectRowAtIndexPath,2)检查图像,3)对触摸没有反应?@dylansturg:是的。。!不是三个,而是两个方面,1。直到检查图像和2。检查图像区域。问题是,如果我只是在调用的图像didSelectRowAtIndexPath方法外轻轻点击,我需要使其可选择。您可以在单元格的特定区域添加点击手势,而不需要实现didSelectRowAtIndexPath方法。我正在使用自定义类来识别图像点击并获得正确的响应。但正如我上面所说的,如果用户在图像边界外轻轻点击,就会触发DidSelectRowatineXpath方法,因此我需要使该区域不可触摸。
    -(void)CrossClicked:(UIButton *)sender{
    
    int index = sender.tag;
    
    //on basis of index you can perform all task
    
    }
    
     class CustomTableViewCell: UITableViewCell {
       var isValidTouch: Bool = true
    
       override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    
        if let touch = touches.first {
           let point = touch.locationInView(self.contentView)
           let validTouchPoint = self.contentView.bounds.width - (checkMarkView.bounds.width + 16.0) //Trailing + Leading space
            if point.x < validTouchPoint {
                isValidTouch = true
            } else {
                isValidTouch = false
                //Send tap gesture callback to your viewcontroller
            }
        }
        super.touchesBegan(touches, withEvent: event)
      }
    
    }
    
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
        let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTableViewCell
        if cell.isValidTouch {
          //do whatever
        }
    }