I have a table view, which is all working well enough but now I would like to have the first cell be an ‘unlock’ button for the remainder of the cells.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [currentPack count] + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Row is %i", indexPath.row);
if(indexPath.row == 0)
{
SoundCell *cell = [SoundCell dequeOrCreateInTable:soundsTable];
cell._NameLabel.text = @"Unlock This Pack;
[cell._startButton setAlpha:0.0];
return cell
}
else
{
SoundCell *cell = [SoundCell dequeOrCreateInTable:soundsTable];
cell._NameLabel.text = [currentPack objectAtIndex:indexPath.row - 1];
return cell
}
}
Now it kind of works, the first cell IS different to the others, and looks exactly as it should. My problem is that for some reason some of the later cells use the
[cell._startButton setAlpha:0.0];
part even though indexPath.row is not 0 when they are made. It doesn’t happen to every cell, just intermittent ones, occasionally if I scroll the table up and down a lot then other cells will pick up this problem too. In every other way the table works fine, selecting a cell triggers the correct response etc.
Does anyone have any idea what could be causing this? It seemed like it would be very simple to implement originally…
Thanks
Use a different reuse identifier for the two cell types so that they don’t mix when reused.
Or add the following line to the rest of the rows: