Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

luke3

macrumors newbie
Original poster
Jun 6, 2012
23
0
I am making a custom header view on my tableview... The custom view has a gradient on it. I only want that gradient to show if it is the only header visible. So if a user is scrolling and happens to see two sections of the tableview, the second section on the tableview should not have a gradient.

What is the best approach to do this?
 
viewForHeaderInSection Layer

I have a custom header view on my tableview. Is there anyway I can get that header view to be one layer above the tableview itself instead of on the same layer? I am trying to have a stationary header view always positioned at the top of the view, and the header view of the tableview to be text. So I need the stationary header to be above the tableview, but below the text...
 
How can I tell when a header is pushed off screen?

I am trying to determine when the section header of the table view becomes pushed off screen.

To get the frame of the rect I am using
Code:
            CGRect headerRect = [self.tableView rectForHeaderInSection:0];
How can I do so?
 
Do you have a ViewController for your view?
If so have a play with the
Code:
- (void)viewWillDisappear:(BOOL)animated
method. See if you can't get that method to at least trigger the chain of events.
 
– scrollViewDidScroll:
– scrollViewWillBeginDecelerating:
– scrollViewDidEndDecelerating:

come to mind. Assign your tableview to the UIScrollViewDelegate
 
You need to do 2 things :
1. Catch the scrollViewDidScroll event to know when the table view is scrolled.
2. Use [tableView rectForHeaderInSection:], but remember that the returned value is a rectangle that is in tableView's coordinate system. You may need to convert that rectangle to other coordinate system (may be from the parent view controller, or from the root window).
 
I am making a custom header view on my tableview... The custom view has a gradient on it. I only want that gradient to show if it is the only header visible. So if a user is scrolling and happens to see two sections of the tableview, the second section on the tableview should not have a gradient.

What is the best approach to do this?

I don't know if this will work, but I can't resist replying (I want someone to try it for me :)).

So the way I am thinking is every table view is a scroll view. Every section is a subview of the scroll view. So every time you scroll, the scroll view must call setFrame: on the section header view to move it.

So if you override setFrame: in your section header view, you will get it's frame. Then you can determine if the section is visible by using CGRectIntersectsRect().

And after that will be the easy part of making UI changes.
 
I have a custom header view on my tableview. Is there anyway I can get that header view to be one layer above the tableview itself instead of on the same layer? I am trying to have a stationary header view always positioned at the top of the view, and the header view of the tableview to be text. So I need the stationary header to be above the tableview, but below the text...

Why don't you use a simple UIView with a label for the section header and add it as a sub view to the table view?
 
Intriguing approach. What does the tableView's scrollview do with that subview? Does it avoid it? Does it scroll behind it?

I've wondered about how to put a sticky header onto a tableview before but never enough to try anything...
 
Intriguing approach. What does the tableView's scrollview do with that subview? Does it avoid it? Does it scroll behind it?

I've wondered about how to put a sticky header onto a tableview before but never enough to try anything...

Ahh.. my bad. The way I described makes no sense. What I meant was to add another view as a sibling to the tableView. Something like this:

Code:
        Container View
               |
               |
               |
        -----------------
        |                |
        |                |
      Table view        section header
 
Oh, that's different.

Ahh.. my bad. The way I described makes no sense. What I meant was to add another view as a sibling to the tableView. Something like this:

Code:
        Container View
               |
               |
               |
        -----------------
        |                |
        |                |
      Table view        section header

Oh. So it would be hard to use a UITableViewController with that situation, just a UIViewController implementing UITableViewDataSource and UITableViewDelegate protocols. That's different - I've done that...
 
Oh. So it would be hard to use a UITableViewController with that situation, just a UIViewController implementing UITableViewDataSource and UITableViewDelegate protocols. That's different - I've done that...

Yes. Usually I never subclass a table view controller, I just use a view controller and implement the table view protocols. That way I get more flexibility.
 
Stacked tableview headers

When my tableview first loads all the section headers are stacked at the top of the view but as soon as you touch the screen and scroll they all jump back into place...

Any ideas on what is going wrong?
 
MOD NOTE: The OP's several threads around tableviews have been merged into this one thread.

OP: May I suggest you read Getting Answers and http://whathaveyoutried.com. It seems that you have started several threads, but have not participated in any follow-on discussion or provided much data for folks to go on here.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.