ios - UITableView, UITableViewCell 内容在设备旋转时消失

标签 ios uitableview

我使用以下代码以编程方式创建了一个 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/

相关文章:

执行自动尺寸时 IOS Swift TableView 边框问题

javascript - iPhone 应用程序 : getting data without a web API

ios - 如何在iPhone 6/6s Plus上保持人像启动屏幕

ios - Swift - 无法从 NSData 创建 JSON 对象

ios - 如何在 uitableview 中动态创建部分

iOS contentStretch 已弃用,如何拉伸(stretch)表格单元格?

ios - 如何针对随 SDK 变化的方法创建单元测试?

ios - Font Awesome ios 图标都一样

ios - UITableViewCell 右侧有图像

ios - 在获取 indexPath 之后但在删除该 indexPath 处的单元格之前调用 reloadData() 是否不安全?