views:

727

answers:

2

In a grouped tableview, the section headers and footers scroll with the cells. However, in a plain tableview, they are fixed to the top and bottom of the screen until the next section is reached.

Is there a way to override this action and make the headers and footers scroll with the cells in a plain tableview?

Thanks!

A: 

Yes. I think the headers you are thinking of are section headers/index that stay over the cells until the next section replaces the current one.

The headers that I am thinking of will scroll off the screen immediately as you scroll down, and there is a similar footer that becomes visible at the very end. HEre is the code I use to set up the header:

- (void)viewDidLoad {
    [super viewDidLoad];
    highScoreData = [HighScoreData get];
    highScoresTable.tableHeaderView = highScoresTableHeaderView;
}

highScoresTableHeaderView is a simple view (IBOutlet) with some labels in my .xib.

@property (nonatomic, retain) IBOutlet UIView   *highScoresTableHeaderView;
mahboudz
Thanks, but I need these to be section headers. Any idea if this is possible?
Jonah
You should then make a cell be your header. In cellForRowAtIndexPath, check the indexpath. If you are at the end of a section or beginning of one, then use that cell as your header. Don't forget to increment your cell count by the number of these header cells. And then add code to prevent the hilighting of these cells or selection of them.
mahboudz
+1  A: 

In a plain tableview I am pretty sure that you cannot change the way sections headers scroll.

BUT, you might be able to get a similar effect. If you leave out the section headers and instead put the header into the first cell of the section, then it will definately scroll the way you want it to.

Then you have to do some work to make the first cell appear to be a header instead of just another cell. That would include delegate functions such as:

To prevent the "header" cell from getting selected:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;

To change the appearance of the "header" cell:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
Kobski