我有一个表格视图,我在其中加载一些 UIButtons 并给它们动态标签。但是标签 = 0 没有为 UIButton 更新。没看懂哪里错了。。。
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];
}
我哪里错了..?