tags:

views:

193

answers:

2

I have a viewController that has a tableView and a custom loading UIView that displays a loading message and spinner while the data of the tableView is being loaded. The custom UIView has a red background that i can see, but i can still see the lines of the tableView, How can i get to display the custom uiview without seeing the tableView lines on the background.

@implementation LoadingView

@synthesize spinner;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
        [self setUserInteractionEnabled:NO];
        [self setBackgroundColor:[UIColor blueColor]];

        // Spinner
        spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [spinner setCenter:CGPointMake(320/2, 150)];
        [self addSubview:spinner];
        [spinner startAnimating];

        //title label
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"Loading...";
        titleLabel.font = [UIFont boldSystemFontOfSize:18];
        titleLabel.lineBreakMode =  UILineBreakModeWordWrap;
        titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.textAlignment = UITextAlignmentLeft;
        CGFloat height = [titleLabel.text sizeWithFont: titleLabel.font constrainedToSize: CGSizeMake(300, 1500) lineBreakMode: UILineBreakModeWordWrap].height;
        [titleLabel setFrame: CGRectMake(120, 180, 100, height)];
        [self addSubview:titleLabel];
        [titleLabel release];

    }
    return self;
}


- (void)drawRect:(CGRect)rect {

}


- (void)dealloc {
    [super dealloc];
    [spinner release];
}


@end
A: 

Hi Benjamin,

You can set the lines "off", when you start you loading process, setting them transparent.


// Setting transparent
tableView.separatorColor = [UIColor clearColor];

And when you remove the loading UIView, you change the color for the one that you want.


// Setting the desired color
tableView.separatorColor = [UIColor grayColor];

Another alternative is to set the table view hidden while you don't have data to be displayed, and than when the first or more row appear you place you set the table view to not hidden.

I hope this will help you!

Cheers,
VFN

vfn
Very interesting. Do you know why this happens?
Benjamin Ortuzar
This happen, because the separators are placed with the table view, even if there is no cell to be displayed....you can check it scrolling your table view , forcing to show where there is no item, on the end of the table, and there you will find many other separators. Why? This is a good question!
vfn
A: 

The problem was that self.view in the viewController had the tableView assigned directly. The solution is to assign the self.view a UIView and add the tableView and the custom UIView on top of self.view.

This is sample code from the viewController.

- (void)loadView {


    UIView *aView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

    //tableView
    self.tableView = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain] autorelease];
    //set the rowHeight once for performance reasons.
    //self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 75;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);                    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.autoresizesSubviews = YES;

    [aView addSubview:tableView];

    //set the rowHeight once for performance reasons.
    self.view = aView;
    [aView release];

}


- (void)viewDidLoad {
    [super viewDidLoad];

    loadingView = [[LoadingView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:loadingView];


    //fetch productsArray
    [self productListRequestStart];

}
Benjamin Ortuzar