How can i show UITableView
Rows only which contains data not the other rows. By default UITableView
shows 10 rows. If we have data for three rows It will display three rows only
How can I implement this? Thank you.

- 51,274
- 23
- 147
- 178

- 281
- 2
- 4
- 10
-
If you want to remove the extra separators below a plain style table view, check out this answer: http://stackoverflow.com/questions/1369831/eliminate-extra-separators-below-uitableview-in-iphone-sdk/1789714#1789714 – albertamg Jun 20 '11 at 11:35
7 Answers
You can set a footer view and make it invisible if you want. Separators will appear only for rows which contain data:
self.theTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)] autorelease];

- 682
- 3
- 14
- 19
I don't think it is possible to hide the extra separators using a standard way. This behavior is preset.
Plain
styled tableView shows the row/separator
even if there are no real rows exist. Only Grouped
styled tableView shows only the existing rows.
Edit: As suggested by others, you can add a footer view to tableView to hide those extra separators.

- 51,274
- 23
- 147
- 178
-
you can eliminate the extra separators by [adding a footer view to the table](http://stackoverflow.com/questions/1369831/eliminate-extra-separators-below-uitableview-in-iphone-sdk/1789714#1789714). – albertamg Jun 20 '11 at 11:39
Just add below code in your viewDidLoad() method.
self.tableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

- 2,272
- 3
- 31
- 43
OK, I assume you are using Interface Builder.
The easy way:
make sure you have chosen your view controller class as both UITableViewDelegate and UITabbleViewDataSource.
In the ViewController.h (or whatever its called) add
<UITableViewDelegate,UITableViewDataSource>
before the { of the @interface definition. to the class that it must conform to those protocols.Make sure the minimal datasource protocol methods are in the class :
– tableView:cellForRowAtIndexPath: – tableView:numberOfRowsInSection:
in the – tableView:numberOfRowsInSection: method return the number of desired rows - 3 or by a bit of code to calculate this property
in the – tableView:cellForRowAtIndexPath: method do what you need to on the cell and return it. Boilerplate code
is:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease]; } cell.text = @"I am a cell"; return cell; }
N.B. If you are not using Interface Builder do: tableView.delegate = self; tableView.datasource = self;
You can specify the required number of rows in the return parameter of the following function :
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return NUMBER_OF_ROWS;
}
For more details please go through the Apple documentation of UITableView.

- 818
- 6
- 22
-
if "data" is your Array/Dictionary with data you can return [data count]; – konradowy Jun 20 '11 at 11:35