Ios 访问UITableView单元格
我在一个单元格上有一个like按钮,旁边显示了like的数量。 我已经在cellForRowAtIndexPath中创建了所有的单元格,并且用它的indexath标记了每个单元格。现在,当有人点击“like”按钮时,我想显示更新的数字,而不必重新加载整个表 为了简单起见,我将展示代码的基本内容: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
-()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++];