Is it possible to have a UITableViewController hide its cells until there's content, and in the meantime display a "no content" message?

ios, objective-c, uitableview, uiview

Solution

Design a no content view (UIView) as you wish, add that view to self.view and position it on top of your table view. Make it hidden initially. Then inside `- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section` method, you can do something like this.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int count = songsArray.count;

    if(count==0){
        self.noContentView.hidden = NO;
    }else{
        self.noContentView.hidden = YES;
    }

    return count;
}

Problem

Similar to how Apple did it in their music app: I want to have a `UITableViewController`, but how would I best go about only showing the cells if there's content, otherwise show that "no content" message. Just put a `UIView` on top of the table view?

Original source