Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display a table with zero rows in UITableView

I am loading a content into UITableView dynamically. If there is data the table needs to display the data. If there is no data the table should display a plain page. But in my application the table displays the plain page with two separator lines. i need to remove this separator line and display a plain white page. Please Suggest?

Any help would be appreciated!

like image 739
Sathiya Avatar asked Sep 29 '09 07:09

Sathiya


4 Answers

If you provide a view to the footer then the separators between the empty rows will disappear.

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
myTableView.tableFooterView = view;
like image 136
bbarnhart Avatar answered Oct 16 '22 11:10

bbarnhart


You could check for the empty case if your datasource is empty add a placeholder view on top of the tableview. If they are not empty, remove the placeholder view.

like image 35
klaaspieter Avatar answered Oct 16 '22 11:10

klaaspieter


A plain UITableView will always display separator lines even if it is empty. You might notice that if you have a list with only one or two rows, there are still separator lines visible. This is the default behaviour and should not be overridden unless you have a really good reason.

I am guessing you see only two separator lines because your rows are very tall?

If you do really need to remove the separator lines then set the separatorStyle property on your table view to UITableViewCellSeparatorStyleNone. Take note that this will affect all rows. So if you still want separators for the rows that do exists, then you must draw these separator lines in your own UITableViewCell objects.

like image 27
PeyloW Avatar answered Oct 16 '22 09:10

PeyloW


It can be simplified to a single line, using @bbarnhart solution:

myTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
like image 40
Diego Acosta Avatar answered Oct 16 '22 11:10

Diego Acosta