-
Re: Unable to cast between types
QuinceyMorris Dec 3, 2016 6:44 PM (in response to Gargoyle)Well, you can't *cast* a superclass to a subclass, because the object (of the superclass) doesn't actually have the additional behavior of the subclass.
What you're going to have to do is "tell" the reusableCell method what subclass to create.
-
Re: Unable to cast between types
eskimo Dec 4, 2016 2:43 PM (in response to QuinceyMorris)What you're going to have to do is "tell" the reusableCell method what subclass to create.
Specifically,
dequeueReusableCell(withIdentifier:for:)
returns a cell of the type determined by looking up theidentifier
parameter in the registered cell classes for table. In most cases you set this up in the interface editor by:Adding a prototype cell to the table view
Using the identity inspector (View > Utilities > Identify Inspector) to set the class for it
Using the attributes inspector (View > Utilities > Attributes Inspector) to set the reuse identifier for it
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Unable to cast between types
QuinceyMorris Dec 4, 2016 3:30 PM (in response to eskimo)Yes, except that because this is crossing a bundle boundary, it's an API decision whether to supply an identifier as a parameter (which needs to be managed depending where the table is defined) or a class (which might mean using registerClass in the framework). I don't think we got enough information to make it clear what the best approach might be.
-
Re: Unable to cast between types
Gargoyle Dec 4, 2016 3:37 PM (in response to QuinceyMorris)So the library was registering the table cells to make things easier on the caller, so it has a function like so:
static func registerCells() { tableView.register(ExpandableDatePickerCell.self, forCellReuseIdentifier: ExpandableDatePickerCell.identifier) tableView.register(ExpandableDatePickerTimeZoneCell.self, forCellReuseIdentifier: ExpandableDatePickerTimeZoneCell.identifier) }
And then in viewDidLoad() of the caller I can just call that. 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?
-
Re: Unable to cast between types
eskimo Dec 5, 2016 1:04 AM (in response to Gargoyle)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 yourviewDidLoad()
callregisterCells()
and then replace the registrations it wants to override?Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Unable to cast between types
Gargoyle Dec 5, 2016 12:09 PM (in response to eskimo)Sweet! I didn't know you could just re-register over the existing name with another class. Thanks!
-
-
-
-