Reputation: 1857
I have a nib in .xib format that defines a tableview cell. It has a certain custom class assigned to it in the IB part of Xcode. I use table.register(StaffCell.nib, forCellReuseIdentifier: StaffCell.reuseID)
where the nib and reuseID are static on the class. We then use table.dequeueReusableCell(withIdentifier: StaffCell.reuseID, for: indexPath) as! StaffCell
to get a cell to use. All is well.
We now have need for a subclass of the custom cell class to be able to be used (in a different view controller, which is a subclass of the main view controller where we are using this). The subclass of the custom class doesn't change anything about the physical connections and the cell views and stuff don't change. The subclass for the cell just changes some logic on the internal parameters.
I'd rather not have to copy and make a new nib (.xib) file just in order to be able to assign a new custom class (which is a subclass of the original). Nothing but the custom class parameter is changing.
Is it possible to someway dynamically change the custom class of the nib before it instantiates the cell?
table.dequeueReusableCell(withIdentifier: StaffCellSubclass.reuseID, for: indexPath) as! StaffCellSubclass
crashes and burns at runtime with an error that it can't coerce the StaffCell into a StaffCellSubclass (I don't have the actual text of the error as it was a co-worker with whom I was team coding that had the actual error on screen). (The reuseID points to the same nib)
Thanks
Upvotes: 0
Views: 205