Question

I'd like to add section headers to my grouped table view's sections but I'd like them to appear seamless (see image). The default, as we're all well aware of, is rounded top corners on the first row of a grouped table view cell so it ends up looking like crap when you merge them.

Any way to specify when indexPath.row = 0 that the UITableViewCell should use row style "middle" or something like that?

If not then what are my options? I guess I could scratch the section header and use Row 0 as a quasi-header then push my array data +1 to fill the rest of the table? I'd rather not roll my own from scratch...if possible.

Sample Table http://img35.imageshack.us/img35/8181/sampletable.png

Edit:

"Crap" looks like this:

alt text http://img25.imageshack.us/img25/9748/crapsection.png

Was it helpful?

Solution

  1. Don't do what you're doing, it's against HIG

  2. Ok, ok, I'll tell you how to do it:

You're going to want to do your own cell background views. The default grouped one is not what you want.

When a tableview asks you for a cell, set its backgroundView and selectedBackgroundView to something that looks appropriate for its place in the tableview.

Usually, this means a UIImageView with the appropriate image, though you can go wild here with a custom view, but there are gotchas.

So in your case, you would do

if (indexPath.row > sectionRowCount - 1) {
    //Not the last row
    //Put in the middle background
} else {
    //Put in the end background
}

Then you'll want a custom table section header, but that's pretty easy.

In your case, you probably won't have to worry about when there's just one row, so that makes things even easier.

OTHER TIPS

Take a look at the tutorial here: cocoa with love basically what you need is 3 different images. One for the top row, one for the bottom, and a 3rd for the middle rows.

You could also not use the section header, but instead use a custom cell as the first cell of the section. So when ([indexPath row] == 0), return a custom cell that is the "header" and then return the "regular" cells (offset by one row) for the rest. You'll also have to make adjustments to the numberOfRowsInSection function to return +1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top