objective-c - 无法更改 UITableView 中的单元格大小

标签 objective-c ios ipad uitableview

我创建 tableViewController 并需要使最后一个单元格更大。但我无法设置我想要的大小。这是我的代码

cell.bounds = CGRectMake(0,45,320,900);
        [[cell.contentView viewWithTag:indexPath.row]removeFromSuperview] ;
        CGRect frame = CGRectMake(20, 20, 400, 500);
        CGRect frame2 = CGRectMake(0, 0, 400, 500);
        [cell setFrame:frame];
        [cell setBounds:frame2];

        //[self tableView].rowHeight = 500;
        UITextView *txtView = [[UITextView alloc] initWithFrame:frame];
        txtView.text = @"SEND FROM MY IPAD";
        txtView.textAlignment = UITextAlignmentLeft;
        [cell.contentView addSubview:txtView];
        [txtView release];

但我可以更改某些像素和所有像素的高度(enter image description here

最佳答案

您需要实现 UITableViewDelegate 协议(protocol)才能更改行(单元格)高度。参见方法tableView:heightForRowAtIndexPath: .

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100.0f;
}

要更改宽度,只需将 UITableView 的宽度设置为所需的值。

关于objective-c - 无法更改 UITableView 中的单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022263/

相关文章:

objective-c - 当改变方向的内存在增加时

ios - 如何仅在三个边上设置 UITextField 边框/CALayer 边框 ios

ios - 在包含 View block 上点击手势 tableView 选择

javascript - iOS 上的 IFrame 高度问题(移动版 safari)

ios - 更新到 Xcode 10.2 后,构建在 testflight 上黑屏

ios - 插入后更改 CAGradientLayer 中的颜色

ios - 切换单元格大小按钮不更改单元格标识符 UIViewController

ios - 使用 AVFoundation 时对什么对象实际包含捕获的图像感到困惑

iphone - 应用程序将进入后台 -> 转到 Root View 菜单

iphone - UIViewController 的高度设置为 460