iOS:滚动时自定义 uitableviewcell 中的按钮的 UIButton 背景图像被删除
iOS: UIButton background image getting removed for button in custom uitableviewcell on scroll
我的自定义 table 视图单元格中有一个 uibutton,不同单元格的按钮具有不同的背景图像。一旦我开始滚动,超出范围的随机单元格就会删除它们的背景图像。我有两个带有两个背景图像的按钮,但它总是为其中一个做
- (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];
...
...
}
请帮忙
使用
[tableView dequeueReusableCellWithReuseIdentifier:@"playerCell" forIndexPath:indexPath];
而不是
[tableView dequeueReusableCellWithIdentifier:@"playerCell"];
我的自定义 table 视图单元格中有一个 uibutton,不同单元格的按钮具有不同的背景图像。一旦我开始滚动,超出范围的随机单元格就会删除它们的背景图像。我有两个带有两个背景图像的按钮,但它总是为其中一个做
- (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];
...
...
}
请帮忙
使用
[tableView dequeueReusableCellWithReuseIdentifier:@"playerCell" forIndexPath:indexPath];
而不是
[tableView dequeueReusableCellWithIdentifier:@"playerCell"];