在 UITableViewCell 中有不同的按钮,当我单击任何按钮时,它的动作正在所有单元格上执行,但我希望当我按下按钮时,动作将显示在同一个单元格的标签上,我知道我需要将它们放入数组中,但如何...?
当我单击按钮时,一个值正在递增,它应该显示在同一单元格的标签上,这里是代码:-
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
likeShow=[[UILabel alloc]initWithFrame:CGRectMake(0, 160, 80, 20)];
likeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[likeBtn addTarget:self action:@selector(likeFn) forControlEvents:UIControlEventTouchUpInside];
likeBtn.frame=CGRectMake(0, 110, 90, 50);
[likeBtn setTitle:@"Like" forState:UIControlStateNormal];
[likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell addSubview:likeBtn];
[cell addSubview:likeShow];
return cell;
}
这是按钮的动作
-(void)likeFn{
NSString *str;
NSMutableString *mystring=[NSMutableString string];
likeCount++;
str =[NSString stringWithFormat:@"%d",likeCount];
NSString *world = @"Like";
NSString *helloWorld = [world stringByAppendingString:str];
likeShow.text=helloWorld;
}