0

I have a UITableView with one section and a header. The problem is that when I scroll down beyond the contents of the table, the header is pulled down along with the cells. I would like it to stay at the top of the view. I tried the suggestion on this post,

Change Default Scrolling Behavior of UITableView Section Header

using the footer of a zero-row section as the header, but it still isn't anchored. Does anyone know how to do this properly?

Community
  • 1
  • 1
serverpunk
  • 10,665
  • 15
  • 61
  • 95

1 Answers1

2

Are you using a UITableViewController? If you are using a UIViewController that contains a UITableView you could just add a UIView above the UITableView.

You could also add the UIView on top of the UITableView and add an alpha gradient to make it look more similar to a regular UITableView section header.

bbarnhart
  • 6,620
  • 1
  • 40
  • 60
  • I'm trying this right now but the table view fills the whole view, even if I set a new frame. Is there any way to restrict this? – serverpunk Feb 05 '12 at 06:54
  • I think you're probably using a UITableViewController if you can not change the frame. Please check. If you are then you will need to switch to a UIViewController with a UITableView inside of it. The UITableViewController is very restrictive. – bbarnhart Feb 05 '12 at 15:52
  • I am using a UIViewController with a UIView and UITableViewController. I eventually got it work by doing everything programmatically, but I believe the table view fills the screen regardless of what view controller you're using if loaded from a nib. – serverpunk Feb 05 '12 at 20:39
  • You should not add a **UITableViewController** to a UIViewController. You should try a **UITableView** in the UIViewController instead. – bbarnhart Feb 06 '12 at 04:06
  • Sorry, I meant to say UITableView. – serverpunk Feb 06 '12 at 06:35