私はUICollectionViewから全く同じセル設定を使用していますが、今回はUITableViewの内部で、この理由は折りたたみ可能なヘッダーを使用しているため、UITableViewにする必要があるためです。コードはUICollectionViewCellの代わりにUITableViewCellになり、xibファイルは異なるはずです。私はどういうわけか、このコードをコピーペーストの代わりにUITableViewCellで再利用できるようにできますか?UITableViewの内部でUICollectionViewCellに同じコードを使用するにはどうすればよいですか?
class LoggedExerciseCell: UICollectionViewCell {
// MARK: - IBOutlets
@IBOutlet var cell: UICollectionViewCell!
@IBOutlet var loggedSetTableView: LoggedSetsTableView!
@IBOutlet weak var exerciseName: UILabel!
@IBOutlet weak var exerciseCount: UILabel!
@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var resistanceType: UILabel!
@IBOutlet weak var repetitionType: UILabel!
// MARK: - Object Lifecycle
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
// MARK: - Configure Cell
func configure(_ exercise: LoggedExerciseViewModelView) {
self.exerciseName.text = exercise.exerciseName
self.icon.image = UIImage(named: exercise.icon)
self.resistanceType.text = exercise.resistanceType
self.repetitionType.text = exercise.repetitionType
self.loggedSetTableView.loggedExerciseViewModel = exercise
}
}
// MARK: - CommonInit
private extension LoggedExerciseCell {
func commonInit() {
Bundle.main.loadNibNamed("LoggedExerciseCell", owner: self, options: nil)
cell.frame = self.bounds
addSubview(cell)
configureViews()
}
}
// MARK: - ConfigureViews
private extension LoggedExerciseCell {
func configureViews() {
configureIconImageView()
}
func configureIconImageView() {
icon.setCircularImageViewWithBorder(borderWidth: 1.2, withBorderColor: UIColor.darkBlue().cgColor)
}
}
セルクラスがあるとしてあなたは、類似したコードではなく、同じコードを使用することができます同じではなく、代議員は異なっています。 – Raptor
その1つのリンクは非常に便利です。https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/ –
私はUICollectionViewでもヘッダーを拡張できると思います。 試してみてください:https://stackoverflow.com/questions/32046292/uicollectionview-header-change-height-in-ibaction – danieltmbr