views:

70

answers:

2

The music app on the iPad has quite a lot of interesting custom UI features, one of which is the table view displayed when looking at the albums of a particular artist.

It has images along the side of each section, almost acting in a very similar fashion to section header views. If I scroll down, the top image stays there until the next image comes along to bump it off, and vice versa.

Initially it seems quite impossible without reimplementing the UITableView all over again, but I think it's semi-doable by simply subclassing a UITableView to draw these section images on the side, outside of the uitableview, whenever it calls layoutSubviews (i.e. whenever it scrolls). There are slight problems with this: because it draws outside of the UITableView, any autoresizing will probably throw the entire layout off. And I'm really just unsure about the feasibility of it all.

Any thoughts?


Edit: I just realized that my first idea wouldn't work in that any touches on the images side themselves wouldn't be tracked by the tableview, so you couldn't scroll if you touched there. I think the biggest issue here is figuring out how to propagate the touches so that touches are tracked across the entire view.

+1  A: 

you could check what section you are in in the tableview (or the topmost etc) somehow, then simply have a UIView that gets updated whenever the section changes, my idea is a bit hard to explain, but it wouldn't have to do with redoing UITableView at all, just have another view beside the table view to do the images instead of trying to embed that functionality.

Another way to do this, is perhaps a bit more tricky but you could try to indent your cells so they dont start at the very left of the table view, make the tableview very wide and have a custom view in the section header that contains that image on its left and hopefully would do it correctly? good question and a fun one to play with.

Jesse Naugher
Actually, a combination of both sounds pretty workable. Adding a subview within the tableview that sits next to the cells, along with "indenting" the cells so the table and the side view doesn't overlap.
David Liu
yes. i believe its a fun UI experiment anyway, and id be interested in seeing if you can get the desired results :)
Jesse Naugher
Well, apparently it's possible, as I did it with my prototype. But it requires a lot of help from the datasource/delegate side as well to "indent" the cells and section headers. Can't figure out how to make all of this self-contained within the tableview itself, but I guess I can't be too picky.
David Liu
I found a better solution as an evolution from my prototype, posted below, but your post gave me a ton of help in figuring it out. Thanks a ton.
David Liu
A: 

After thinking about it randomly in the middle of the night, I finally figured out a real solution.

Embed the UITableview in a UIScrollView, and when the user scrolls the view, the touches go through through the parent scrollview, and not the tableview itself. Pretty much everything you need to do lies in the layoutSubviews method; since layoutSubviews of the scrollview is called whenever the user scrolls the view, just change the frame of the tableview to stay fixed onscreen, and change the tableview's contentOffset to match that of the scrollview.

Example code:

- (void) layoutSubviews{
    tableView.frame = CGRectMake(self.contentOffset.x, self.contentOffset.y, tableView.frame.size.width, tableView.frame.size.height);
    tableView.contentOffset = self.contentOffset;   
}

At this point, you can adjust the tableview to one side, and do whatever you want on the other.

David Liu