Samuli Lehtonen Samuli Lehtonen - 4 months ago 38
iOS Question

A placeholder text to tableview if the datasource is empty

I want to display a text to user to inform that there is no content in the data source. For example you can see this kind of behavior in contacts App if you don't have contacts it says it at the middle of the table with gray text. Is there easy way to do this or do I have to use some trick like creating empty cells or something.. Thanks!


There isn't (AFAIK) any built-in way to have a table view display a message when empty. You could have tableView:numberOfRowsInSection: return 1 if the datasource is empty and tableView:cellForRowAtIndexPath: return a "dummy" cell saying there is no data. Or you could just add your own view to display the appropriate message, ignoring the (empty) table view completely.