How to create a UITableView that can scroll horizontally?

こ雲淡風輕ζ 提交于 2019-12-21 22:37:24

问题


I am trying to create a verticalTableView that has a horizontalTableView inside each verticalTableViewCell that can scroll horizontally (same concept as the 'Pulse' app). And I have found a number of tutorials (two examples below), but they are all in the days of XIBs. Can anyone explain how to do it/give me a link to a tutorial on how to do the same with a Storyboard instead?

First Tutorial

Second Tutorial

Update: I have since found another question on SO that was answered by the same person that asked the question. This person has managed to implement the protocols for a tableView using a UITableViewCell class, question is how? And does it matter that the tableView that contains the dynamic tableView is static?

dynamic UITableView in static UITableViewCell


回答1:


Use the below part of code to create the required table.

    UITableView *horizontalTable = [[UITableView alloc] init];
    [horizontalTable setDelegate:self];
    [horizontalTable setDataSource:self];
    horizontalTable.transform = CGAffineTransformMakeRotation(-M_PI * 0.5);
    horizontalTable.autoresizesSubviews=NO;
 frame =CGRectMake(140, 0 , 642, 85);
//frame is important this has to be set accordingly. if we did not set it properly, tableview will not appear some times in the view
[self.view addSubview:customTable];

and in the custom cell's CustomCell Class, we find the below method.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

in that method, use this.

 self.transform = CGAffineTransformMakeRotation(M_PI * 0.5);



回答2:


Thanks to @christoph, I finally figured it out. See sample code in his question.

dynamic UITableView in static UITableViewCell



来源:https://stackoverflow.com/questions/10779032/how-to-create-a-uitableview-that-can-scroll-horizontally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!