How to fix the header and first row in a UITableView
I´m new trying to make some apps using objective c, so I´ve an idea using uitableview but I don't imagine how can I get this.
I´m trying to do something like you do in a spre开发者_如何学Cadsheet where you have a fixed header and the first column too
So when scroll the uitableview vertically the header will stay visible at top of the table and rows will change
And finally when you scroll in horizontal direction the first cell of the row will stay visible and will change the header depending of how you scroll the uitableview
I hope you could give me an idea how to get this, because I don't imagine how to do this, also I don´t have a lot of experience with this programming language.
Thanks!
In a non-grouped table, section headers "stick" at the top of the table as the table scrolls. You can provide a custom UIView
(or sub-class thereof) for a section header through the delegate method –tableView:viewForHeaderInSection:
. This header view could be created on-the-fly programmatically or loaded from a NIB file. Either way, you can have it contain whatever you want, even update it as the app runs (provided you have given yourself access through ivars or class variables to the views contained in your header view.) If you go this route, you'll want to be clever about allocating resources that comprise this view, so that you are not constantly allocating new resources! This delegate method can be called frequently, and on all but the first call you could simply return the previously created (but updated as and if necessary) header view.
UITableView
isn't designed to do this, although I am sure you could figure out some way eventually.
My approach would be to use a fixed UIView
of some sort (possibly a UILabel
, etc) in a UIViewController's
nib as the header/locked cell, and add the UITableView
under that. You couldn't then use a UITableViewController
, but would have to implement the delegate
and dataSource
methods in your UIViewController
, and use a UISwipeGestureRecognizer
to pick up the gestures from the tableView and update the other views.
I've done this by adding a UIView that mimics the first cell in my table. In my case I am using a subclass of UITableViewCell, but that is perhaps not relevant. Normally this view is hidden with an alpha of 0.
If you view controller is the delegate of the UITableView then it will also be the delegate for the inherited UIScrollView. So in your view controller you can implement scrollViewDidScroll. When the scrollView's contentOffset is positive I set my custom view's alpha to 1 (I also do some small size tweaks to make sure there is a perfect match), and when the contentOffset returns to 0 or negative, I reset the alpha back to 0.
prepend the first row of data in your array to what ever in the first row is your headings, put the text in bold with attributed text, It wont be sticky but you will have headings...
精彩评论