Juan
Juan

Reputation: 77

how to do horizontal scroll tableview

I need to do a horizontal scroll in my table view and I search for all the Google and I don't find anything, I do that

CGRect tableFrame = CGRectMake(15, heightView-360, widthView+50, heightView-200);
UITableView *tableView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
tableView.layer.cornerRadius=7;
tableView.rowHeight = 40;
tableView.sectionFooterHeight = myData.count;
tableView.sectionHeaderHeight = myData.count;
tableView.scrollEnabled = YES;
tableView.showsVerticalScrollIndicator = YES;
tableView.showsHorizontalScrollIndicator=YES;
tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
tableView.userInteractionEnabled = YES;
tableView.bounces = YES;
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];

what are wrong? why don't go the horizontal scroll?

Upvotes: 2

Views: 9942

Answers (4)

Gitesh Agarwal
Gitesh Agarwal

Reputation: 1

Follow these steps to make a scrollable horizontal table view :

  1. Subclass UIView and create a table view with appropriate frames.
  2. Rotate the table view by -90 degrees ( self.tableView.transform = CGAffineTransformMakeRotation(-M_PI_2);).
  3. Set Autoresizing mask (self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);).
  4. Create a cell View and rotate it by 90 degrees and populate the table view with that cell.
  5. implement - (void)handleTapGestureRecognizer:(UITapGestureRecognizer *)tapGesture; delegate method to get the location of the tapped cell and scroll to it automatically.

Hope that helps!!!!

Upvotes: -1

Nils Ziehn
Nils Ziehn

Reputation: 4331

What you are looking for is a UICollectionView, not a UITableView. Here you can implement cells and scroll in either direction.

In Interface Builder when you select the CollectionView it has a property called 'Scroll Direction' - change that to 'horizontal'

Upvotes: 5

iAnurag
iAnurag

Reputation: 9356

Please take a look at this. This should solve your problem.

https://github.com/alekseyn/EasyTableView

I did this when I was Stuck:

CGRect frame = tblView.frame;
tblView.transform = CGAffineTransformRotate(stressTblView.transform, M_PI / 2);
tblView.frame = frame;

Upvotes: 1

JordanC
JordanC

Reputation: 1323

From the docs

enter image description here

You were able to access properties related to horizontal scrolling because UITableView is a subclass of UIScrollView, but they aren't meant for use in UITableView

Upvotes: 2

Related Questions