tilo
tilo

Reputation: 14169

Best approach: Displaying a "nothing here, yet" screen instead of empty tableView cells

When opening a UITableViewController, I'd like to display a screen saying "nothing here, yet" (c.f. screenshot of the Dropbox App below) instead of empty rows when there are no sections/rows. This is done in multiple Apps already, but I'd like to know if there is a recommended way of achieving this.

Dropbox: empty favorites tab

I can imagine multiple ways of doing this, including

Thank you for all your ideas!

Upvotes: 1

Views: 760

Answers (3)

tilo
tilo

Reputation: 14169

There is a new (as of June 2014) library called DZNEmptyDataSet handling exactly this case. It uses the first approach (UIView as a subview) described in the question. Pretty neat realisation.

Upvotes: 1

iphonic
iphonic

Reputation: 12719

You must be having some data array through which you can define few things, in table view.. You can achieve this in your tableview only with its delegate methods..

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if([dataArr count] == 0)
     return 1;
    return [dataArr count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
      if([dataArr count]==0){
          return self.view.frame.size.height;

      }
  return 44.0;
}

and then

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     if([dataArr count]==0){
        //Create a cell with the no data image
        tableView.scrollEnabled=NO;
     }else{
         //Create your default cell with data..
         tableView.scrollEnabled=YES;
     }

   return nil;
}

I am just giving you an idea, its your choice of using it..

Upvotes: 0

Zaphod
Zaphod

Reputation: 7270

The way I usually do it, is displaying a single custom cell when there's nothing to display.

Upvotes: 1

Related Questions