I am trying to implement the table view with 4 cells in each section and number of section is also 2. I added the buy button in last two rows of each sections and make them hidden till row is not selected. When I click on last row of the first section, the buy button appears. However, as soon as I tap on last row of second section (last section) than it do not appears. Here is my code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
// some code for cell properties
if(indexPath.section==0)
{
if(indexPath.row==2)
{
//some code for property of buy button1
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = buyButton1;
[buyButton1 setHidden:YES];
}
if(indexPath.row==3)
{
//some code for property of buy button2
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = buyButton2;
[buyButton2 setHidden:YES];
}
}
if(indexPath.section==1)
{
if(indexPath.row==2)
{
//some code for property of buy button3
[cell addSubview:buyButton3];
[buyButton3 setHidden:TRUE];
}
if(indexPath.row==3)
{
buyButton4= [UIButton buttonWithType:UIButtonTypeRoundedRect];
buyButton4.frame = CGRectMake(194, 4, 70, 37);
[buyButton4 setTitle:@"Buy" forState:UIControlStateNormal];
[buyButton4 addTarget:self action:@selector(buyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
buyButton4.tag = 4;
[cell addSubview:buyButton4];
[buyButton4 setHidden:TRUE];
}
}
}
if(indexPath.section == 0)
{
cell.textLabel.text = [privateArray objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text = [workArray objectAtIndex:indexPath.row];
}
return cell;
}
Here is my code for selection of row
- (void)tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableViewForOccasion deselectRowAtIndexPath:indexPath animated:NO];
NSArray *visibleCells = [tableViewForOccasion visibleCells];
for (UITableViewCell *aCell in visibleCells)
{
aCell.accessoryType = UITableViewCellAccessoryNone;
}
if(indexPath.section==1)
{
if(indexPath.row==3)
{
[buyButton4 setHidden:FALSE];
}
}
}

since you are talking about the last row in the second section then your checking condition is wrong