UITableView Section Header Not Float?

Discussion in 'iOS Development' started by Steaps, Dec 2, 2009.

  1. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    How could I make the section header not float over the cell when scrolled, but rather scroll above the cell, like if I were using "UITableViewStyleGrouped" (I'm using UITableViewStylePlain, as I need the cells to be custom, and you can't draw custom cells when it's set to Grouped).

    Any help?

    Please Register or Log in to view images

  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Why can't you draw custom grouped table cells? I can. Other developers can.

    Here's an image where I draw thr foreground and background. And as evidenced by the section header being half scrolled off screen, this is most certainly a grouped table.

    Please Register or Log in to view images



    Also, I'm not sure which methods you're referring to needing. A grouped table cell is exactly the same thing as a plain table cell.


    Here's another horrid example. If you can't get it (hint, you're thinking too hard), wait for me to release FailKit. It has a convenience method in it to change the color if the PTTableCell, regardless of whether it is plain or grouped.

    Please Register or Log in to view images

    If you really insist on going with a plain table cell with static headers, you will need to subclass UITableView.
  3. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    For the grouped tableview cell, it doesn't use anything in the drawRect, i want to draw an image over the cells, which works great in plain, but in grouped none of my custom drawing is drawn.

    After reading every line in the header, came up with this:

    Code:
    self.backgroundView.alpha = 0.0;
    self.selectedBackgroundView.alpha = 0.0;
    
    It says it's set to nil when UITableViewStyle is UITableViewStylePlain, but setting it to nil shows the cell still sometimes. I don't really like just setting the alpha or hidden to 0, possibly releasing it.. hmm.

    Ahh! removing those two objects from the superview does the trick

    Please Register or Log in to view images

    .
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Actually, it is not doing the trick. It look like it is, but it isn't. What you're looking at is the difference between
    what you're doing: http://www.skylarcantu.com/images/SkyPhone3/CSPreview1.png
    and what you should be doing: http://www.skylarcantu.com/images/SpyPhone/PTThemes3.png

    Notice the difference?

    Of course, if you want to simply add a image to the cell, then add the image as a subview of the cell's contentView. That's the overall recommended approach to it.


    Also, you do need to look in the drawRect: That's where the answer lies. Again though, you're probably overthinking it.



    Of course, my implementation of my default table view subclass detects whether or not it is a plain or grouped table cell, then calls the appropriate method: Literally, this is my code:
    [OBJC]- (void)drawRect

    Please Register or Log in to view images

    CGRect)rect {
    isGroupCell ? [self drawGroupedCellRect:rect] : [self drawPlainCellRect:rect];
    }[/OBJC]

    My -drawGroupedCellRect: method is only nine lines long (one more than my -drawPlainCellRect: method because I need to know the cell's position in the group and draw accordingly).

    Slow down and take a step back.

Share This Page