我使用以下代码以编程方式创建了一个 UITableView
[self createUITableView:categoryTableView
frame:CGRectMake(0, [UIApplication currentSize].height - ([UIApplication currentSize].height*0.2) - self.navigationController.navigationBar.frame.size.height - 20, [UIApplication currentSize].width,[UIApplication currentSize].height * 0.2)
tag:1
rotation:CGAffineTransformMakeRotation(-M_PI_2)];
-(void)createUITableView :(UITableView*)tableView frame:(CGRect)frame tag:(NSInteger)tag rotation:(CGAffineTransform)rotation
{
tableView = [[UITableView alloc]init];
tableView.transform = rotation;
tableView.frame = frame;
tableView.dataSource = self;
tableView.delegate = self;
tableView.backgroundColor = [UIColor greenColor];
tableView.tag = tag;
tableView.showsHorizontalScrollIndicator = false;
tableView.showsVerticalScrollIndicator = false;
tableView.bounces = false;
[self.view addSubview:tableView];
}
旋转表格 View 后,我将旋转单元格以正确显示内容
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
cell.transform = CGAffineTransformMakeRotation(M_PI_2);
cellImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, widthforTableView,tableView.frame.size.height )];
[cell.contentView addSubview:cellImage];
cell.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell.layer.borderWidth = 0.5f;
//cell.textLabel.textAlignment = NSTextAlignmentCenter;
cellImage.backgroundColor = [UIColor blueColor];
}
当我旋转设备时,我调整 UItableview 的大小并更改位置以很好地适应屏幕,我还调整 tableview 行高的大小并调用 tableview reloadData
但是由于 tableviews 调整大小,我发现 tableview 单元格的内容消失了。
cell.textlabel 消失,并且添加了任何其他自定义 View 。
一旦使用 MPI 旋转单元格,它似乎只会影响 tableview ???
所以我的问题是:-
当您调整/旋转包含的表格 View 时,如何防止单元格内容消失?
最佳答案
将单元格的 contentView 框架设置为单元格边界,然后将其 autoresizingMasks 设置为灵活高度和灵活宽度。
关于ios - UITableView, UITableViewCell 内容在设备旋转时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26550057/