xcode 如何创建一个可以水平滚动的 UITableView?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10779032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a UITableView that can scroll horizontally?
提问by tarheel
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?
我正在尝试创建一个 verticalTableView,它在每个可以水平滚动的 verticalTableViewCell 中都有一个 horizontalTableView(与“Pulse”应用程序的概念相同)。而且我找到了一些教程(下面有两个例子),但它们都是在 XIB 时代。任何人都可以解释如何做到这一点/给我一个关于如何用故事板做同样的教程的链接?
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?
更新:此后我在 SO 上发现了另一个问题,该问题由提出该问题的同一个人回答。这个人已经设法使用 UITableViewCell 类实现了 tableView 的协议,问题是如何?包含动态 tableView 的 tableView 是静态的是否重要?
采纳答案by tarheel
Thanks to @christoph, I finally figured it out. See sample code in his question.
感谢@christoph,我终于弄明白了。请参阅他的问题中的示例代码。
回答by Ganesh
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.
在自定义单元格的 CustomCell 类中,我们找到了以下方法。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
in that method, use this.
在那个方法中,使用这个。
self.transform = CGAffineTransformMakeRotation(M_PI * 0.5);