動的な行数で 4 つのセクションを作成UITableView
しました。セルをカスタマイズし、ボタンを非常にセルに追加しました。ボタンは別のセクションで再利用されています。
私のコード:
- (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;
}
なぜそれが起こったのか理由を付けて適切な解決策を教えてください