I want implement a layout in my ipad application that has a uitable view that scrolls left and right rather then up and down :
So rather than
row 1 row 2 row 3 ( scrolling vertically ) It would be : row 1, row2, row 3 (scrolling horizontally )
I've seen that UItableView is designed to only do vertical scrolling so doing a transform does not give the desired effect. Is there a standard way to do this taking advantage of a datasource provider like uitableview provides?
I basically want to do somthing similar to what the BBC News reader app on the Ipad does with the list of stories to select from.
Thanks
There is a simple brilliant trick to get a UITableView to do both vertical and horizontal scroll perfectly.
You can do it both with and without autolayout - I will explain it with autolayout.
On you UITableView have a width constraint and no tailing alignment constraint. The bind this width constraint with an IBOutlet and in your controller set the following to properties on the table view.
The tableview needs to be full width to render all the content in the horizontal direction, and the we plays with the content size compared with screen size that does the trick.
The following locations of them below works but you can try the in different steps in the lifecycle:
If you can restrict your app to only iOS 6 and upwards, the best way to do this is with UICollectionView.
If you need to support iOS 4/5, then try one of the opensource reimplementations of UICollectionView, eg. PSTCollectionView
I have published sample code that demonstrates one approach for implementing horizontally scrolling table views using transforms. It's called EasyTableView and provides the same interface for both vertically and horizontally scrolling table views.
For now you have to use UIScrollView and set scrolling to horizontal only. As for the data you need handle the dequeing and optimizations yourself. If you do not expect more than a dozen or so objects then you can probably skip it, but if they are data intensive try to implement a similar data sourcing and loading as UITableView uses. Note that the BBC News reader app also uses paging enabled to scroll by each 'page (4 or so news icons)'.
This is the method that I use:
1) Implement you own subclass of UITableView and override its
initWithCoder:
method as shown below:2) Create your own UITableViewCell class and override
initWithCoder:
again:3) Now you can create a UITableView element in IB and set its class to be "MyHorizontalTableView" in the identity inspector.
4) Create your UITableViewCell element in IB and set its class to be "MyHorizontalTableViewCell" in the identity inspector.
And that's it.
This would work by overriding other initializers too in case you prefer not to use IB to instantiate your table view or cell.
A sample project that I built around this concept can be found in GitHub.
This question has been answered by apple. Scrolling example by apple
this works for iPad also.