Can we add a scroll view inside UITableViewCell?

12,449

Solution 1

Of course you can add scrollView in tableView.

 UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];            
 [cell.contentView addSubview:scrollView];

Now you can set properties for scroll view accordingly.

Solution 2

Yes it is definitively possible and reasonable.

Here is an excellent tutorial by Felipe Laso that explains it step by step:

How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 1

How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 2

BTW, the approach described in that tutorial is way more efficient than adding a UIScrollview to each cell.

Share:
12,449
thatguy
Author by

thatguy

Updated on June 04, 2022

Comments

  • thatguy
    thatguy almost 2 years

    I have requirement where I have to show some images which are differentiated according to Groups they belong to. I have used a table view to view images listed under groups. User has to scroll horizontally to view more images in a particular group. Can we add a scroll view to tableview row to allow user to scroll list of images horizontally? I searched a bit, some comments say its not allowed in apple's HIG some comments say You can add a UIScrollView to a UITableViewCell and as long as you set the contentSize property of the UIScrollView correctly then the UIScrollView will scroll correctly in the horizontal axis

    May I get any confirmation on this ?? Or any alternative approach to achieve horizontal and vertical scrolling for different data without using tableview

  • JonB
    JonB over 12 years
    The HIG was made to be broken.
  • Joe Masilotti
    Joe Masilotti over 11 years
    Do you have any sources proving that nested UITableViews are more efficient than UIScrollViews? I dont' see anything in the links you provided.
  • Felix
    Felix over 11 years
    UITableView is a UIScrollView subclass that is more efficient because it can reuse cells. In a scroll view you would have lots of sub views that all consume memory at the same time.