Wolfert
Wolfert

Reputation: 974

Tableview lines show trough loading view

Situation: I'm trying to display a loading screen while waiting for my asynchronous connection to return with data to populate the tableview.

Problem: Creating and adding the loadingscreen works fine, however, the tableview draws its lines over it, see screenshot:

the problem .

Code: I add the view with these lines:

-(void) viewDidLoad{
    [super viewDidLoad];

    _loadScreen = [[LoadScreen alloc] initWithFrame:self.view.bounds];
    [self.view addSubview: _loadScreen];
    [self fetchRemoteData];
}

Question: Is it possible to add the loading view ontop of the table? Or can i make sure the tableview does not draw its lines untill i call reloadData?

-Thanks in advance, W

Upvotes: 0

Views: 461

Answers (2)

lukewar
lukewar

Reputation: 2715

There is some approaches that will solve you problem:

-Set a footer view for the table view, so all lines should disappear.

self.tableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

-I assume that you use UItableViewController. If so self.view and self.tableView both represents the same view, so by setting:

self.tableView.hidden = NO;

It will hide even your loading view. What I encoure you to do is to create a custom view which has an table view as its subview. Then you can hide this table view by only showing an loading view.

Hope I could help.

Upvotes: 0

Nick Weaver
Nick Weaver

Reputation: 47241

I've done it like this many times:

-(void) viewDidLoad{
    [super viewDidLoad];

    _loadScreen = [[LoadScreen alloc] initWithFrame:self.view.bounds];
    [self.tableView addSubview: _loadScreen];
    self.tableView.hidden = YES;
    [self fetchRemoteData];

}

- (void)dataFetchedSuccessfully
{
    self.tableView.hidden = NO;
}

Just hide the tableview and show it again when the data has been loaded.

Upvotes: 1

Related Questions