UITableViewCell 中的旋转 UITableView 未显示 initWithFrame: 的位置

Posted

技术标签:

【中文标题】UITableViewCell 中的旋转 UITableView 未显示 initWithFrame: 的位置【英文标题】:rotated UITableView within UITableViewCell not showing where initWithFrame: says to 【发布时间】:2012-06-09 19:00:51 【问题描述】:

我有一个 UITableViewController,它有一个 UITableViewCell 的子类,每个单元格都有一个 UITableView。我有两个 UITableViews 工作得很好。当我旋转它时,问题就来了。如果我将 tableViewInCell 的框架设置为比包含单元格的高度更大的宽度,那么它就会变得混乱。见下文。

tableView 的宽度设置为一个值

tableViewInCell = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 132, 132) style:UITableViewStylePlain];

tableView的宽度设置为一个值>包含tableViewCell的高度:

tableViewInCell = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 132, 320) style:UITableViewStylePlain];

如何让 tableViewInCell 填充包含 UITableViewCell 的宽度而不是乱线?

更新:

tableViewInCell = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 132) style:UITableViewStylePlain];

更新 2:这是我设置 tableViewInCell 的方法。

-(void)setupTableView 

tableViewInCell = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 132) style:UITableViewStylePlain];
[tableViewInCell setDelegate:self];
[tableViewInCell setDataSource:self];
tableViewInCell.transform = CGAffineTransformMakeRotation(-M_PI * .5);
[self addSubview:tableViewInCell];


【问题讨论】:

如果将 (132, 320) 更改为 (320, 132) 会发生什么 在问题中查看我的屏幕截图更新。 你能发布一些关于你如何旋转桌子的代码 发布了在 initWithStyle:reuseIdentifier: 方法中调用的 setupTableView: 方法的代码。 调用您发布的新代码会破坏视图吗? 【参考方案1】:

将您当前的setupTableView 更改为

-(void)setupTableView 
    tableViewInCell = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 132 , 320) style:UITableViewStylePlain];
    tableViewInCell.transform = CGAffineTransformMakeRotation(-M_PI * .5);
    tableViewInCell.frame = CGRectMake(0, 0, 320, 132);
    [tableViewInCell setDelegate:self];
    [tableViewInCell setDataSource:self];
    [self addSubview:tableViewInCell];


【讨论】:

以上是关于UITableViewCell 中的旋转 UITableView 未显示 initWithFrame: 的位置的主要内容,如果未能解决你的问题,请参考以下文章

UITableVIewCell 重叠图像中的自定义按钮

自定义 UITableViewCell 中的 UIButton 在旋转后停止工作

UITableViewCell 中的旋转 UITableView 未显示 initWithFrame: 的位置

在旋转时更改 UITableViewCell 中的文本对齐方式

如何在 UITableVIewCell 中进行 API 调用

旋转时,从 UITableViewCell 显示的 UIPopoverController 放置不正确