0

全部

同一个问题可能以不同的方式问了很多次。但我的情况有些不同。

我有大约 10 个单元格的表格,现在每个单元格都有不同的自定义控件(即 UILabel、UIButton)等。

现在我希望当我单击单元格 0 上的按钮时,它会更改同一单元格上的标签(自定义 UILabel 而不是单元格标签)值,而无需重新加载整个表格。

在此处输入图像描述

4

2 回答 2

1

是的,是您的自定义单元格类,您像这样将属性分配给 UiButton

@property(strong,nonatomic) IBOutlet UIButton *btnAdd;

以及此方法中的下一件事

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

你写这样的代码

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

在这个类中写下这段代码

   -(void)AddMethod:(UIButton *)btnAdd
  {
  NSIndexPath *indexPath=[NSIndexPath indexPathForRow:btnAdd.tag inSection:0]; // if section is 0
            customcell *cell = (customcell*)[maintableView cellForRowAtIndexPath:indexPath];
  cell.yourlabelname.text=[NSString stringWithFormat:@"%d",[yourlabelname.text intValue] + 1];
   }
于 2013-07-17T11:33:27.493 回答
0

您可以更新 UITableview 的特定单元格,只需存储该行的 indexPath 并使用以下方法对其进行更新。

[self.myTablviewname beginUpdates];

[self.myTablviewname reloadRowsAtIndexPaths:[NSArray arrayWithObject:button.indexPath]    withRowAnimation:UITableViewRowAnimationNone];

[self.myTablviewname endUpdates];

您也可以根据自己的方便为行提供动画。

于 2013-07-16T13:43:01.653 回答