0

like my question, i just want to ask somebody who made an application that use background for his/her tableview and tableviewcell. Cause i have a problem with those background. Here is my app pic with the problem alt text

i use graycolor for background in tableview and whitecolor for background in tableviewcell, i want to make all cell that containt a text have a whitecolor background, but i can't do it. here's my code

-(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]]; 

}

is there something wrong in my code??

R. Dewi
  • 4,141
  • 9
  • 41
  • 66
  • u have written, "i want to make all cell that containt a text have a whitecolor background", y do u need cells whick does not contain any text> and how many rows u want to show in table. make it clear please. after that I may help. – Developer Dec 13 '10 at 05:53
  • hhmmm...maybe 10 row in that table, the text are fill from array – R. Dewi Dec 13 '10 at 07:35
  • then u should write in ur "noOfRowsInSection" return [yourArray count]; and please provide the link for ur code I will update that as I am not getting your question clearly. One more thing: What does it mean? if([filemodels.fileExpanse compare:@"display"]==0){ backgroundView.backgroundColor = [UIColor whiteColor]; }else{ backgroundView.backgroundColor = [UIColor whiteColor]; } in both cases output is same. – Developer Dec 13 '10 at 07:55
  • thx for your help Harsh, the array count already added into "noOfRowsInSection", but it's still like my pic. But dont worry, i've found the answer, i write in answer – R. Dewi Dec 13 '10 at 08:41

1 Answers1

0

i already read the link that Derek gave to me, and i found a code that i can use. I've decided to use image for cell background and table background. and this is my code to answer this question

-(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

}

and i added

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

into viewDidLoad method, and finally...this problem is solved. Thx everyone... (n_n)

R. Dewi
  • 4,141
  • 9
  • 41
  • 66