views:

131

answers:

1

Is there a right way to add empty table text? For example, if you go to the simulator and open contacts, the table is empty and displays "No Contacts". Or searching that gives a "no results" message via the UISearchDisplayController.

I could do this via a label positioned and hidden at run time, but is this the correct approach?

Thanks for your help

A: 

I think if you want to do like: 1/ Search: a big view (may be not need to be a table view) having a text "No Results". You can remove and add tableView at runtime. For example, you can have a view A contains a label "No Results" and a tableView to contain results. Then, when user search and no results, you add the view A. If there is a result, you remove view A and add tableView

2/ Like Contacts: it seems to be easier. You can override the method: // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; }

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return a cell contaning a text "No Contacts" }

vodkhang
Thank you. I hadn't tried moving an empty table with the message so hadn't detected it was part of the table view.