我创建UITableView
了 4 个具有动态行数的部分,我自定义了单元格并将按钮添加到非常单元格,按钮在不同的部分中重复使用。
我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
self.buttonMe = [UIButton buttonWithType:UIButtonTypeCustom];
[ self.buttonMe setFrame:CGRectMake(260.0, 7.0, 30.0, 30.0)];
self.buttonMe.tag=i;
if([[arrayCheckUnchek objectAtIndex:indexPath.row] isEqualToString:@"Uncheck"])
[ self.buttonMe setImage:[UIImage imageNamed:@"check.gif"] forState:UIControlStateNormal];
else
[ self.buttonMe setImage:[UIImage imageNamed:@"uncheck.jpg"] forState:UIControlStateNormal];
[ self.buttonMe addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview: self.buttonMe];
cell.textLabel.text=@"itsFine";
//"i", i created for assigning the unique tag for created button every time
i++;
return cell;
}
请给我适当的解决方案,说明为什么会发生谢谢