Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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单元格_Ios_Uitableview_Uibutton - Fatal编程技术网

Ios 访问UITableView单元格

Ios 访问UITableView单元格,ios,uitableview,uibutton,Ios,Uitableview,Uibutton,我在一个单元格上有一个like按钮,旁边显示了like的数量。 我已经在cellForRowAtIndexPath中创建了所有的单元格,并且用它的indexath标记了每个单元格。现在,当有人点击“like”按钮时,我想显示更新的数字,而不必重新加载整个表 为了简单起见,我将展示代码的基本内容: -()cellForRowAtIndexPath{ ... cell.Plus.tag = indexPath.row; [cell.Plus addTarget:self action:@selec

我在一个单元格上有一个like按钮,旁边显示了like的数量。 我已经在cellForRowAtIndexPath中创建了所有的单元格,并且用它的indexath标记了每个单元格。现在,当有人点击“like”按钮时,我想显示更新的数字,而不必重新加载整个表

为了简单起见,我将展示代码的基本内容:

-()cellForRowAtIndexPath{
...

cell.Plus.tag = indexPath.row;
[cell.Plus addTarget:self action:@selector(plusBtnClick:) forControlEvents:UIControlEventTouchUpInside];

...
}



-(void) plusBtnClick:(id)sender{
//update the number
}

如果您的按钮是单元格内容视图的子视图,
MyCell*cell=[[sender superview]superview]
将为您提供指向包含单元格的指针。使用
cell.likeLabel.text=whatEverValue更新文本

我必须使用标记创建nsindepath。请参阅下面的代码,我将其放入plusBtnClick函数中

NSIndexPath *plusIndexPath = [NSIndexPath indexPathForRow:senderButton.tag inSection:0];
CustomTableViewCell *cell = (CustomTableViewCell *)[self.tableView cellForRowAtIndexPath:plusIndexPath];
cell.ScoreLabel.text = [NSString stringWithFormat:@"%ld", (long)scoreCount++];