Bri*_*yle 2 iphone background-image uitableview ios
我已经使用UIAppearance在我的应用程序中设置表格单元格的背景图像.
[[UITableViewCell appearance] setBackgroundView:[ [UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"list_bg.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]];
Run Code Online (Sandbox Code Playgroud)
但是,当我查看列表时,仅为屏幕上的一个单元格设置背景图像.如果我滚动屏幕,背景图像将设置在出现在视图中的单元格上,但它不会在任何其他可见单元格上设置此bg图像.
任何人都知道发生了什么事吗?我认为通过设置UITableviewCell的UIAppearance,这种类型的所有实例都会自动获取背景图像.
谢谢
布赖恩
这是我的cellForRowAtIndexPath方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"plantCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"PlantListCell" owner:self options:nil];
cell = _plantCell;
self.plantCell = nil;
}
Plant *plant = [self.fetchedResultsController objectAtIndexPath:indexPath];
UIImageView *thumbnail = (UIImageView *)[cell viewWithTag:1];
thumbnail.image = [UIImage imageNamed:[plant.name stringByAppendingString:@"_S"]];
UILabel *label = (UILabel *)[cell viewWithTag:2];
label.text = plant.name;
UIImageView *set = (UIImageView *)[cell viewWithTag:3];
set.image = [UIImage imageNamed:@"set"];
UIImageView *favourite = (UIImageView *)[cell viewWithTag:4];
favourite.image = [UIImage imageNamed:@"fav"];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
是的.这个问题是你告诉UITableViewCell类为每个表格视图单元格的背景视图设置一个UIImageView.一旦设置为1,就将其从之前的superview中删除,并添加到新的UITableViewCell中.你没有在每个tableViewCell上设置重复的UIImageViews; 你在每个表视图单元格上获得了一个视图集.
然后从每个tableViewCell设置和取消设置,直到它设置的最后一个.
使用此方法的外观代理将其设置在UITableViewCell的每个对象上.
我不会使用外观代理来设置背景视图方法,因为传递给它的任何视图都是一个视图,它一次只能应用于一个单元格.
我的建议是独立地为每个单元创建一个视图,或者创建一个在初始化时设置它的子类.
| 归档时间: |
|
| 查看次数: |
3822 次 |
| 最近记录: |