UITableViewCell にはさまざまなボタンがあり、ボタンをクリックするとすべてのセルでそのアクションが実行されますが、ボタンを押すと同じセルのラベルにアクションが表示されるようにしたいのですが、必要なことはわかっていますそれらを配列に入れるにはどうすれば...?
ボタンをクリックすると、1 つの値がインクリメントされ、同じセルのラベルに表示されます。コードは次のとおりです。
-(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;
}