いくつかのUIButtonをロードして動的タグを与えるテーブルビューがありますが、UIButtonのtag = 0は更新されません。どこが間違っているのか理解できませんでした...
int i=-1;
@synthesize......
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
btnTemp = [[UIButton alloc]initWithFrame:CGRectMake(10,lblName.frame.origin.y+lblName.frame.size.height+3,17, 17)];
[btnTemp addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btnTemp.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[btnTemp setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnTemp.titleLabel.font =[UIFont systemFontOfSize:14.f];
btnTemp.tag=++i;
return cell;
}
しかし、初めてこのメソッドに入ると、UIButtons タグの値が 0 に更新されません。
-(IBAction) btnClicked:(UIButton *) sender{
UIButton *button = (UIButton *)sender;
NSLog(@"%d", [button tag]);
UIButton *btnTemp = (UIButton*)[cell viewWithTag:0]; //Here UIButton is being converted to UItableViewCell and getting error.
[buttonsinaSection addObject:btnTemp];
}
どこが間違っているのでしょうか..?