I am having some trouble with adding a button to a table cell.
The table is grouped but the data comes from a single array. I want to have the first cell display an "add" button. I have managed to get all of this to work with one problem.
When I scroll the table the button shows up on other cells in a random manner.
Here is the code snippet:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
int matchingIndex = ((indexPath.section *2)+ indexPath.row);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
[[cell textLabel] setText:[currentLocation objectAtIndex:matchingIndex]];
if (matchingIndex == 0) {
//insert button here
UIButton *button = self.contactAddButtonType;
[cell.contentView addSubview:button];
}
return cell;
}
Any ideas?
Deanne