【问题标题】:is there somebody who made an application using background for tableview and tableviewcell?有没有人为 tableview 和 uitableviewcell 使用背景制作应用程序?
【发布时间】: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


【解决方案1】:

我已经阅读了 Derek 给我的链接,并且我找到了可以使用的代码。我决定使用图像作为单元格背景和表格背景。 这是我回答这个问题的代码

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if(_segmentedControl.selectedSegmentIndex == 0){
        FileModel *filemodels = [_filemodels objectAtIndex:indexPath.row];
        if([filemodels.fileExpanse compare:@"display"]==0){

            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"whiteColor.png"];

        }else{
            ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"whiteColor.png"];

        }
    }

    [[self tableView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"grayColor.png"]]]; //tableview background using image

}

我加了

[[self tableView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"grayColor.png"]]]; //tableview background using image

进入viewDidLoad方法,终于……这个问题解决了。谢谢大家... (n_n)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多