Monday, 9 September 2013

Want to add a button to few cells in TableView

Want to add a button to few cells in TableView

I have 9 rows in my tableview and want to add buttons to only row 1 and 2.
When first time the code runs, it shows button on 1 and 2. But when I
scroll the tableview, it starts randomly showing for row 4,5,8,9. The code
is below. Please advice what I am doing wrong.
- (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];
}
cell.textLabel.text = [NSString stringWithFormat:@"Row %d",[indexPath
row]];
if([indexPath row] == 0 || [indexPath row] == 1)
{
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
return cell;
}

No comments:

Post a Comment