_FieldCell supports only one style of cell. the constraints on fieldCell are being created on the func customConstraints.
I can subclass _FieldCell and override customConstraints, but that way I would have to create my own versions of almost all Eureka Rows that depend on _FieldCell.
This is my feature request! I think it would be a great addition.
Thanks for the work! 馃憤
I'm working on a similar problem at the moment and I agree that subclassing all the subclasses is the only way I've been able to make it work.
E.g., I have some custom setup in the _FieldCell to give it the appearance of UITableViewCellStyle.value2:
open class _MyFieldCell<T>: _FieldCell<T> where T: Equatable, T: InputTypeInitiable {
open override func setup() {
super.setup()
tintColor = .red
titleLabel?.font = .caption1
row.title = row.tag // Sets the title of the row to be its tag by default
}
open override func update() {
super.update()
textField.textAlignment = .left
textField.font = .body
textField.clearButtonMode = .whileEditing
}
override open func customConstraints() {
super.customConstraints()
guard imageView?.image == nil, let titleLabel = titleLabel, let text = titleLabel.text, !text.isEmpty else { return }
contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 89)) // The constant is where the magic happens, change that to change the width of the label.
}
}
And now I subclass copy TextCell:
open class MyTextCell : _MyFieldCell<String>, CellType {
required public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open override func setup() {
super.setup()
textField.autocorrectionType = .default
textField.autocapitalizationType = .sentences
textField.keyboardType = .default
}
open override func update() {
super.update()
}
}
open class _MyTextRow: FieldRow<MyTextCell> {
public required init(tag: String?) {
super.init(tag: tag)
}
}
public final class MyTextRow: _MyTextRow, RowType {
required public init(tag: String?) {
super.init(tag: tag)
}
}
And unless I'm doing something very wrong, this has to be repeated for every row type. Some clearer guidance on subclassing rows for beginners would be appreciated, I don't want to use clumsy nibs for simple tasks, but there are so many protocols and classes involved I end up copying a lot of code.
On the subject, I why does putting .value2 in super.init(style: style, reuseIdentifier: reuseIdentifier) not work?
.subtitle cell style for anyone interested in this
Most helpful comment
1468 was merged recently adding support for
.subtitlecell style for anyone interested in this