Ios 目标-C(发送者)

Ios 目标-C(发送者),ios,objective-c,xcode,Ios,Objective C,Xcode,我有一个自定义单元格的tableView,它有一个segmentControl。我需要让每个细胞都能捕捉到她控制的状态。我已经知道我的头在旋转,我找不到错误。你能帮我吗 h。文件分段控制: m。文件单元: m。具有表视图的文件: 在这种情况下,您需要使用协议和委托方法。 在您的cell.m中创建代理名称: - (void)tableView:(UITableView *)tableView segmentedControl:(UISegmentedControl *)segmentControl

我有一个自定义单元格的tableView,它有一个segmentControl。我需要让每个细胞都能捕捉到她控制的状态。我已经知道我的头在旋转,我找不到错误。你能帮我吗

h。文件分段控制:

m。文件单元:

m。具有表视图的文件:


在这种情况下,您需要使用协议和委托方法。 在您的cell.m中创建代理名称:

- (void)tableView:(UITableView *)tableView segmentedControl:(UISegmentedControl *)segmentControl changedValueAtIndex:(NSIndexPath *)indexPath;
然后在你的手机里打电话

- (IBAction)changed1:(id)sender
然后在tableview.m中实现它,您将获得修改值,因为您在param中有segmentControl。

您所需要的只是通过valueChanged事件触发changed1函数的UISegmentedControl的NSIndexPath,然后您将确切地知道从何处触发操作。不需要像现在这样将indexPath存储为变量

// Place this in your viewController
- (IBAction)changed1:(id)sender{
    CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView]; 
    NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];
    // Now you know exactly which segmented control actually fired this action. 
}

// Set self as the target
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //
    [cell.segmentMeating addTarget:self action:@selector(changed1:) forControlEvents:UIControlEventValueChanged];
    //
}

在你的m。具有表视图的文件,segmentMeatingtarget不应是表视图本身,而是单元格:


因为,您的目标操作在Cell类中。T

我认为您可能必须实现一些委托,以获得每行的每个分段控件。请记住,表视图重用单元格。每次调用addTarget:action时,您都会再添加一个listener@vichevstefan这是自我,零-搜索的结果error@Claudio事实证明确实如此。使用声明的字段按钮\u indexpath可以将其更改为segmentMeeting吗?我想这是关于某人的会议,而不是关于肉、香肠、鱼等?谢谢你的帮助,它在iOS8工作,在iOS7不工作。我仍然需要支持早期版本。我可以获取发生更改的单元格编号segmentControl,但我无法执行操作以获取此segmentControl的状态。您不能执行操作是什么意思?changed1UIControlEventValueChanged事件触发是否已更改?如果没有,您是否设置了addTarget:self?它在iOS8工作,在iOS7不工作。在ios7执行后更改1获取它:[ViewController changed1:]:未识别的选择器发送到instance1您将更改1放置在何处iAction?这需要在你的cell类之外。您将使用此操作获取segmentedControl的indexPath。在.h segmentControl的帮助下,我可以获取活动单元格的编号,在.m With tableView的帮助下,我发送一个请求,以使用为.h segmentControl编号指定的单元格内容执行操作。最后,在.m cell的帮助下,我在change1中执行必要的操作,change1已经获得了内容和数字。但是解决方案已经找到了,请查看页面顶部。是的,是的!谢谢你的帮助!
- (void)tableView:(UITableView *)tableView segmentedControl:(UISegmentedControl *)segmentControl changedValueAtIndex:(NSIndexPath *)indexPath;
- (IBAction)changed1:(id)sender
// Place this in your viewController
- (IBAction)changed1:(id)sender{
    CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView]; 
    NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];
    // Now you know exactly which segmented control actually fired this action. 
}

// Set self as the target
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //
    [cell.segmentMeating addTarget:self action:@selector(changed1:) forControlEvents:UIControlEventValueChanged];
    //
}
   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        cell.segmentMeating.button_indexPath = indexPath;
        [cell.segmentMeating addTarget:cell action:@selector(changed1:) forControlEvents:UIControlEventValueChanged];