【发布时间】:2011-05-24 11:00:45
【问题描述】:
就像我的问题一样,我只是想问一个为他/她的 tableview 和 tableviewcell 制作了使用背景的应用程序的人。因为我对这些背景有疑问。这是我有问题的应用图片
我在 tableview 中使用 graycolor 作为背景,在 tableviewcell 中使用 whitecolor 作为背景,我想让所有包含文本的单元格都具有白色背景,但我做不到。 这是我的代码
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
UIView* backgroundView = [ [ [ UIView alloc ] initWithFrame:CGRectZero ] autorelease ];
//--new color code--
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"celltable_root.png"]];
cell.backgroundView = backgroundView;
for ( UIView* view in cell.contentView.subviews )
{
if(_segmentedControl.selectedSegmentIndex == 0){
FileModel *filemodels = [_filemodels objectAtIndex:indexPath.row];
if([filemodels.fileExpanse compare:@"display"]==0){
backgroundView.backgroundColor = [UIColor whiteColor];
}else{
backgroundView.backgroundColor = [UIColor whiteColor];
}
}
view.backgroundColor = [ UIColor clearColor]; //set cell background
}
[[self tableView] setBackgroundColor:[UIColor grayColor]];
}
我的代码有问题吗??
【问题讨论】:
-
你写过,“我想让所有包含文本的单元格都有白色背景”,你需要不包含任何文本的单元格>以及你想显示多少行桌子。请说清楚。之后我可以帮忙。
-
hhmmm...该表中可能有 10 行,文本从数组中填充
-
那么你应该写在你的“noOfRowsInSection”返回[yourArray count];并请提供您的代码的链接,我会更新它,因为我没有清楚地了解您的问题。还有一件事:这是什么意思? if([filemodels.fileExpanse compare:@"display"]==0){ backgroundView.backgroundColor = [UIColor whiteColor]; }else{ backgroundView.backgroundColor = [UIColor whiteColor]; } 在这两种情况下输出是相同的。
-
感谢您的帮助苛刻,数组计数已经添加到“noOfRowsInSection”中,但它仍然像我的照片。不过别担心,我已经找到答案了,我写在答案中
标签: iphone uitableview background