【问题标题】:How to create a UITableView that can scroll horizontally?如何创建一个可以水平滚动的 UITableView?
【发布时间】:2012-06-02 11:44:31
【问题描述】:

我正在尝试创建一个verticalTableView,它在每个可以水平滚动的verticalTableViewCell 内都有一个horizo​​ntalTableView(与“Pulse”应用程序的概念相同)。而且我找到了许多教程(下面两个示例),但它们都是在 XIB 时代。谁能解释一下如何做/给我一个教程链接,说明如何用故事板做同样的事情?

First Tutorial

Second Tutorial

更新:此后,我在 SO 上发现了另一个问题,该问题由提出该问题的同一个人回答。这个人已经设法使用 UITableViewCell 类实现 tableView 的协议,问题是如何?而且包含动态tableView的tableView是静态的有关系吗?

dynamic UITableView in static UITableViewCell

【问题讨论】:

  • 使用 storboard techotopia.com/index.php/…techotopia.com/index.php/… 创建表的教程
  • 本教程确实展示了如何获取 UITableViewCell 来定义 UITableViewController 中原型单元格的行为。我仍然需要帮助的部分是如何在 UITableViewCell 中获取整个 UITableView(水平方向)。

标签: iphone objective-c xcode ios5 storyboard


【解决方案1】:

使用以下部分代码创建所需的表。

    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];

在自定义单元格的CustomCell类中,我们找到下面的方法。

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

在那个方法中, 用这个。

 self.transform = CGAffineTransformMakeRotation(M_PI * 0.5);

【讨论】:

  • 我应该把第一个sn-p代码放在哪里?在verticalTable的cellForRowAtIndexPath:里面?
  • NO 你必须把它放在 VIewDidLoad 或其他你想添加水平表的地方
【解决方案2】:

感谢@christoph,我终于弄明白了。请参阅他的问题中的示例代码。

dynamic UITableView in static UITableViewCell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 2017-01-26
    • 1970-01-01
    • 2017-02-16
    • 2012-05-05
    • 2011-04-23
    相关资源
    最近更新 更多