You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift+Storyboard开发:UITableView单元格被压缩缩小问题求助

UITableView自定义单元格在iPad 7th gen运行时被压缩缩小问题排查

两天前开始用Swift和Storyboard开发学校项目APP,完成基于ContentView的UITableView自定义单元格设计后,发现iPad 7th gen真机运行时单元格被压缩缩小,和Storyboard里的设计效果完全不符。

相关截图

代码片段

自定义单元格代码

// 自定义ContentView单元格实现
class CustomTableViewCell: UITableViewCell {
    @IBOutlet private weak var titleLabel: UILabel!
    @IBOutlet private weak var detailLabel: UILabel!
    @IBOutlet private weak var iconImageView: UIImageView!

    override func awakeFromNib() {
        super.awakeFromNib()
        // 初始化样式设置
    }

    func configure(with data: CellData) {
        titleLabel.text = data.title
        detailLabel.text = data.detail
        iconImageView.image = data.icon
    }
}

ViewController代码

class MainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet private weak var tableView: UITableView!

    private let dataSource: [CellData] = (0..<15).map {
        CellData(title: "项目\($0)", detail: "详情描述\($0)", icon: UIImage(systemName: "folder")!)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        tableView.delegate = self
        // Storyboard已关联单元格,未额外注册
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomTableViewCell else {
            return UITableViewCell()
        }
        cell.configure(with: dataSource[indexPath.row])
        return cell
    }
}

struct CellData {
    let title: String
    let detail: String
    let icon: UIImage
}

求助点

请帮忙排查可能导致单元格被压缩的原因,比如Auto Layout约束设置、UITableView行高配置、Storyboard单元格尺寸设置冲突等问题。

内容的提问来源于stack exchange,提问作者Pixel Coin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 07:20:28