Greg
Greg

Reputation: 8340

How to detect a section in a table view is out of view?

There is a table view with three sections. The last section may contain many items. I need to show a button on the navigation bar as soon as the table view is showing only the last section (e.g. user scrolled the cells up so that the first and second view became invisible).

So basically how to detect that the table view is now showing only the last section and cells from the first two sections are no longer visible?

Upvotes: 0

Views: 946

Answers (3)

Sierra Alpha
Sierra Alpha

Reputation: 3727

UITableView class has to methods:

- (NSArray *)indexPathsForVisibleRows;
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;

Have you tried them? Do they help?

Upvotes: 2

cocoakomali
cocoakomali

Reputation: 1356

You can use the tableview delegate to check which section cells are being created by checking it's indexpath.

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Or you can use the below function to get cells that are visible and then check for to which section it belongs to.

  • (NSArray *)indexPathsForVisibleRows;

Upvotes: 0

Casey Fleser
Casey Fleser

Reputation: 5787

You could try to iterate over UITableView's indexPathsForVisibleRows to see if the cells in the relevant section are contained in the array.

Upvotes: 0

Related Questions