Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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/23.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
Iphone 选择UITableViewCell AccessoryView,与选择行分开_Iphone_Objective C_Ios_Uitableview - Fatal编程技术网

Iphone 选择UITableViewCell AccessoryView,与选择行分开

Iphone 选择UITableViewCell AccessoryView,与选择行分开,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我有一个UITableview,显示一些任务,每行都有一个复选框来标记任务是否完成 我希望在用户点击复选框时切换复选标记,并在用户点击行时切换到详细视图。后者很简单,只需使用 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 但是,我想分离选择区域,当选择了accessoryview时只切换复选框,而只有在选择了单元格的其余部分时才进入详细视图。如果我在acce

我有一个
UITableview
,显示一些任务,每行都有一个复选框来标记任务是否完成

我希望在用户点击复选框时切换复选标记,并在用户点击行时切换到详细视图。后者很简单,只需使用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
但是,我想分离选择区域,当选择了
accessoryview
时只切换复选框,而只有在选择了单元格的其余部分时才进入详细视图。如果我在
accessoryview
中添加
ui按钮
,用户只想点击复选框时就会选择行和
ui按钮,对吗

另外,如果用户只是通过拖动
accessoryview
在tableview中滚动怎么办?这不会触发触碰时
ui按钮的动作吗


有人知道怎么做吗?谢谢你的时间

如何管理此委托方法中的附件抽头:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
编辑:

对于响应
AccessoryButtontAppedForrowWithXPath:
方法的自定义accessoryView,可以执行类似的操作

cellforrowatinexpath:
方法中-

BOOL checked = [[item objectForKey:@"checked"] boolValue];
UIImage *image = (checked) ? [UIImage   imageNamed:@"checked.png"] : [UIImage imageNamed:@"unchecked.png"];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];

[button addTarget:self action:@selector(checkButtonTapped:event:)  forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;

- (void)checkButtonTapped:(id)sender event:(id)event
{
   NSSet *touches = [event allTouches];
   UITouch *touch = [touches anyObject];
   CGPoint currentTouchPosition = [touch locationInView:self.tableView];
   NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
   if (indexPath != nil)
  {
     [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
  }
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
  NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];
  BOOL checked = [[item objectForKey:@"checked"] boolValue];
  [item setObject:[NSNumber numberWithBool:!checked] forKey:@"checked"];

  UITableViewCell *cell = [item objectForKey:@"cell"];
  UIButton *button = (UIButton *)cell.accessoryView;

  UIImage *newImage = (checked) ? [UIImage imageNamed:@"unchecked.png"] : [UIImage imageNamed:@"checked.png"];
  [button setBackgroundImage:newImage forState:UIControlStateNormal];
}

如何让自定义附件按钮回拨到表视图的代理?哇,我不知道我怎么会错过这个,很抱歉这个愚蠢的问题,谢谢你的帮助!我来试一试,听起来这正是我要找的。@Carlvaezey说得好,文档中说accessoryButtonTappedForRowWithIndexPath响应的是披露按钮附件类型,这不是我想要使用的类型,因为我想要一个复选框。我可以通过使用“详细视图”的“披露”按钮,点击行的其余部分在行的其他位置切换复选标记来解决这个问题,但这不是我想要的。是的,我希望多年来我都能使用该委托方法@哦,如果你有如何做到这一点的提示,不要坚持!是的,我通常会做类似的事情,尽管我只是处理点击,而没有进一步的重定向,假装它来自委托方法。