luke3's tableview questions thread

Discussion in 'iOS Programming' started by luke3, Jun 20, 2012.

  1. luke3 macrumors newbie

    Joined:
    Jun 6, 2012
    #1
    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?
     
  2. luke3 thread starter macrumors newbie

    Joined:
    Jun 6, 2012
    #2
    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...
     
  3. luke3 thread starter macrumors newbie

    Joined:
    Jun 6, 2012
    #3
    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?
     
  4. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #4
    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.
     
  5. forum user macrumors regular

    Joined:
    Aug 28, 2008
    #5
    – scrollViewDidScroll:
    – scrollViewWillBeginDecelerating:
    – scrollViewDidEndDecelerating:

    come to mind. Assign your tableview to the UIScrollViewDelegate
     
  6. namanhams macrumors regular

    Joined:
    Jun 3, 2009
    #6
    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).
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Can we ask why you need to know this? What are you trying to achieve?
     
  8. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #8
    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.
     
  9. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #9
    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?
     
  10. Ron C macrumors member

    Joined:
    Jul 18, 2008
    Location:
    Chicago-area
    #10
    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...
     
  11. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #11
    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
    
     
  12. Ron C macrumors member

    Joined:
    Jul 18, 2008
    Location:
    Chicago-area
    #12
    Oh, that's different.

    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...
     
  13. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #13
    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.
     
  14. luke3 thread starter macrumors newbie

    Joined:
    Jun 6, 2012
    #14
    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?
     
  15. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #15
    is your numberofrowsinsection method implemented correctly? try putting some logs in there..
     
  16. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #16
    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
     

Share This Page