Handling an empty UITableView. Print a friendly message

前端 未结 22 1193
青春惊慌失措
青春惊慌失措 2020-12-04 05:22

I have a UITableView that in some cases it is legal to be empty. So instead of showing the background image of the app, I would prefer to print a friendly message in the scr

22条回答
  •  悲&欢浪女
    2020-12-04 06:16

    I have been using the titleForFooterInSection message for this. I don't know if this is suboptimal or not, but it works.

    -(NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section   {
    
        NSString *message = @"";
        NSInteger numberOfRowsInSection = [self tableView:self.tableView numberOfRowsInSection:section ];
    
        if (numberOfRowsInSection == 0) {
            message = @"This list is now empty";
        }
    
        return message;
    }
    

提交回复
热议问题