[英]UITableview : Change cell height dynamically when clicked the custom button
[英]UITableView with custom control, change value of UILabel when particular button pressed on cell
所有
相同的问题可能以不同的方式多次提出。 但是我的情况有所不同。
我的桌子上大约有10个单元格,现在每个单元格都有不同的自定义控件(即UILabel,UIButton)等。
现在我想当我单击单元格0上的按钮时,它在同一单元格上更改label(自定义UILabel而不是单元格标签)值,而无需重新加载整个表。
是的,是您的自定义单元格类,您可以像这样将属性分配给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];
}
您只需存储该行的indexPath并使用以下方法对其进行更新,就可以更新UITableview的垂直单元格。
[self.myTablviewname beginUpdates];
[self.myTablviewname reloadRowsAtIndexPaths:[NSArray arrayWithObject:button.indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.myTablviewname endUpdates];
您也可以根据需要方便地将动画排成一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.