UITableView Last cell

How can I know when the last cell of UITableView is being shown, when data is coming from database and I don't know the exact number of cells.

Upvotes: 1

Views: 3414

Answers (3)

Oleg Danu
Oleg Danu

Reputation: 4159

If you know your number of cells in the table and you wish to just know when the last row will appear, you could implement:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

and compare the row with your table rowcount. This method it being triggered just before a row to be shown.

Upvotes: 2

Moshe
Moshe

Reputation: 58067

The proper way to handle a table view is to define a number of sections and a number of rows in each section for your table view in the table view controller. If you don't know the length of the table, you're already in trouble.

A common way to handle this is to load your data from the database into an array and then use the length of the array as the table length. Once you have that, the UITableViewController class should have some sort of method for getting the index path of the last cell. Once you have that you call '[indexPath row]' and you're golden. Read up on UITableViews it's a complex subject if you go into depth.

Upvotes: 1

Kshitiz Ghimire
Kshitiz Ghimire

Reputation: 1716

-(NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section 

this function returns the no of cell from ur table view

Upvotes: 1

Related Questions