Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal UITableView

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

like image 960
imran Avatar asked May 20 '10 02:05

imran


People also ask

Can UITableView scroll horizontal?

Using the horizontally scrolling cells of the UITableView enables us to develop a highly intuitive interface. It also enables the user to glance a lot of information (9 titles in the picture above).

How do I make my UICollectionView scroll horizontal?

You need to reduce the height of UICollectionView to its cell / item height and select " Horizontal " from the " Scroll Direction " as seen in the screenshot below. Then it will scroll horizontally depending on the numberOfItems you have returned in its datasource implementation.

What is a UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.

Is UITableView scrollable?

Smooth Scrolling:- As a result, it affects the smoother scrolling experience. In UITableVIew, Scrolling will be smooth through cell reuse with the help of prepareForReuse() method.


2 Answers

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.

like image 191
aleksey Avatar answered Sep 28 '22 06:09

aleksey


This is the method that I use:

1) Implement you own subclass of UITableView and override its initWithCoder: method as shown below:

- (id)initWithCoder:(NSCoder *)aDecoder {     assert([aDecoder isKindOfClass:[NSCoder class]]);      self = [super initWithCoder:aDecoder];      if (self) {          const CGFloat k90DegreesCounterClockwiseAngle = (CGFloat) -(90 * M_PI / 180.0);          CGRect frame = self.frame;         self.transform = CGAffineTransformRotate(CGAffineTransformIdentity, k90DegreesCounterClockwiseAngle);         self.frame = frame;          }      assert(self);     return self; } 

2) Create your own UITableViewCell class and override initWithCoder: again:

- (id)initWithCoder:(NSCoder *)aDecoder {     assert([aDecoder isKindOfClass:[NSCoder class]]);      self = [super initWithCoder:aDecoder];      if (self) {          const CGFloat k90DegreesClockwiseAngle = (CGFloat) (90 * M_PI / 180.0);          self.transform = CGAffineTransformRotate(CGAffineTransformIdentity, k90DegreesClockwiseAngle);     }      assert(self);     return self; } 

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.

like image 43
diegoreymendez Avatar answered Sep 28 '22 05:09

diegoreymendez