LoginSignup
0
1

More than 3 years have passed since last update.

Xcode12 tableViewの表示エラー

Last updated at Posted at 2020-10-08

Xcode12にアップデートしたらシミュレーター でtableViewが表示エラーを起こした。

tableViewCellに、直接addSubviewできなくなったらしい。

contentView.addSubview(...)

に変更。

import UIKit

 class SearchCell: UITableViewCell {

    let collectionImageView: CustomImageView = {
        let iv = CustomImageView()
        iv.contentMode = .scaleAspectFill
        iv.clipsToBounds = true
        return iv
    }()

    let titleLabel: UILabel = {
        let label = UILabel()
        label.font = .boldSystemFont(ofSize: 18)
        label.textColor = .white
        label.numberOfLines = 0
        label.sizeToFit()
        return label
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)

        contentView.addSubview(collectionImageView)
        collectionImageView.anchor(top: nil, left: leftAnchor, bottom: nil, right: nil, paddingTop: 0, paddingLeft: 8, paddingBottom: 0, paddingRight: 0, width: 95, height: 95)
        collectionImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true        

        contentView.addSubview(titleLabel)
        titleLabel.anchor(top: topAnchor, left: collectionImageView.rightAnchor, bottom: bottomAnchor, right: rightAnchor, paddingTop: 8, paddingLeft: 8, paddingBottom: 8, paddingRight: 8, width: 0, height: 0)
        self.selectionStyle = .none
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1