我有一个 uitableView,在每一行我有 4 个按钮,所有按钮的名称都是“W”,
当我运行程序时:第一行的前 4 个按钮只有“W”
当我滚动我的表格时,我会得到更多的按钮名称“W”
有谁知道是什么问题?
提前致谢
我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
int column = 4;
for (int i=0; i<column; i++) {
// position in the parent view and set the size of the button
UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(0.5+83*i,10, 80,115)];
myButton.tag=(column*indexPath.row)+i;
[cell.contentView addSubview:myButton];
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
myButton.backgroundColor = [UIColor whiteColor];
UILabel *btnTitle = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 30, 10)];
[btnTitle setText:@"W"];
[btnTitle setTextColor:[UIColor blackColor]];
[myButton addSubview:btnTitle];
}
return cell;
}