In an extranal library that I pull in via a pod I've got this class defined.
open class ExpandableDatePickerCell : UITableViewCell {
public static func reusableCell(for indexPath: IndexPath, in tableView: UITableView) -> ExpandableDatePickerCell {
return tableView.dequeueReusableCell(withIdentifier: ExpandableDatePickerCell.identifier, for: indexPath) as! ExpandableDatePickerCell
}
}
Obviously there's some other stuff, that's the interesting method. Then in my project I inherit from that cell.
final class UserProfileDatePickerCell : ExpandableDatePickerCell {
When I hit tableView(_:cellForRowAt:) I'm trying to now get one of those cells, but it's crashing. I call it like so:
let cell = UserProfileDatePickerCell.reusableCell(for: indexPath, in: tableView) as! UserProfileDatePickerCell
But it's getting a SIGABRT with the message:
Could not cast value of type 'ExpandableDatePicker.ExpandableDatePickerCell' (0x103ed3e60) to 'TeamKnect.UserProfileDatePickerCell' (0x103807c78).
I don't understand why it can't do the cast since it's a child.
QuinceyMorris wrote:
Yes, except that because this is crossing a bundle boundary …
Ah, yes, missed that bit.
Gargoyle wrote:
How would I modify the signature of that method where I could optionally pass in a different class to use if they decided to subclass the time zone cell, for example?
Do you need to?
register(_:forCellReuseIdentifier:)
allows you to replace a registration (by calling it again with the same reuse identifier), so why not have your
viewDidLoad()
call
registerCells()
and then replace the registrations it wants to override?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"