Is there anyone who made a bid using the background for tableview and tableviewcell?

like my question, I just want to ask someone who made an application using the background for his / her tableview and tableviewcell. Because I have a problem with this background. Here is my pic application with problem alt text

I use graycolor for the background in tableview and whitecolor for the background in tableviewcell, I want the whole cell containing the text to have a whitecolor background, but I cannot do this. here is 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?

0
source share
2 answers

Look at this article about cocoa with love . I think it covers what you ask.

0

, , , . . ,

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

0

Source: https://habr.com/ru/post/1776606/


All Articles