Reputation: 1462
I have a uibutton in my custom table view cell which has different background image for a button for different cell. As soon as i start scrolling, random cells which were out of scope removes their background image. I have two button with two background image but it is always doing for one of them
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
...
PlayerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"playerCell"];
if(cell == nil) {
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PlayerTableViewCell" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[PlayerTableViewCell class]])
cell = (PlayerTableViewCell *)currentObject;
}
}
numberImage = [self getUserImage:[self._collectionsNewGame[indexPath.row -1] objectForKey:@"hostBirthday"] isSign:false];
signImage =[self getUserImage:[self._collectionsNewGame[indexPath.row -1] objectForKey:@"hostBirthday"] isSign:true];
cell.numberButton setBackgroundImage:[UIImage imageNamed:numberImage] forState:UIControlStateNormal];
[cell.signButton setBackgroundImage:[UIImage imageNamed:signImage] forState:UIControlStateNormal];
...
...
}
Please Help
Upvotes: 0
Views: 223
Reputation: 1942
Use
[tableView dequeueReusableCellWithReuseIdentifier:@"playerCell" forIndexPath:indexPath];
instead of
[tableView dequeueReusableCellWithIdentifier:@"playerCell"];
Upvotes: 1