S.C.
S.C.

Reputation: 2874

Is there a way to determine what is the "top" section header of a UITableView?

Is there a way to determine what is the "top" section header of a UITableView?

For "top section header" I mean the section header that is sticky at the top of the UITableView bounds.

Upvotes: 1

Views: 1425

Answers (3)

ferdil
ferdil

Reputation: 1300

If you mean the TABLE header (and the TABLE footer) - not the SECTION header/footer, then you access it through tableHeaderView a property of the UITableView

tableHeaderView Returns an accessory view that is displayed above the table.

@property(nonatomic, retain) UIView *tableHeaderView

If you want the SECTION header, then you need to create it by implementing the UITableViewDelegate method -tableView:viewForHeaderInSection:

tableView:viewForHeaderInSection: Asks the delegate for a view object to display in the header of the specified section of the table view.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

Upvotes: 0

Tim Davies
Tim Davies

Reputation: 834

You'll want to use the -(UIView) viewForHeaderInSection method. This will allow you to use your own UI view as the header for the table view section.

Upvotes: 0

Constantino Tsarouhas
Constantino Tsarouhas

Reputation: 6886

You can get the section number using this:

NSUInteger sectionNumber = [tableView indexPathForCell: [[[tableView visibleCells] objectAtIndex: 0] section]];

I hope that helps.

Upvotes: 2

Related Questions