Reputation: 4480
I have created a structure for different Cell Identifiers:
enum CustomCellIdentifiers
{
static let cellForCountry = "cellForCountry"
static let cellForCity = "cellForCity"
static let cellForStoreType = "cellForStoreType"
}
and I am registering the cell to the table as per switch case, like:
view.tableForItems.register(UINib.init(nibName: cellIdentifier, bundle: nil), forCellReuseIdentifier:cellIdentifier)
but when I registered the cell I got at error that the reuseIdentifier
is nil:
class CustomTableCell: UITableViewCell
{
override func awakeFromNib()
{
super.awakeFromNib()
// Initialization code
switch self.reuseIdentifier ?? "cellForCountry" //It only work with country cell
{
case CustomCellIdentifiers.cellForCountry:
print("cellForCountry") break;
case CustomCellIdentifiers.cellForCity:
print("cellForCity") break;
case CustomCellIdentifiers.cellForStoreType:
print("cellForStoreType")
break;
default: break
}
}
}
Upvotes: 0
Views: 2145
Reputation: 2714
set reUseIdentifier
in the xib
file too.
if you are not able to set the reuseIdentifier in xib class means you created xib file from UIView. Instead
Take the UITableviewcell Class to create xib not the UIView..
then you are able to assign reuseIdentifier from xib file
Please see the image below
Upvotes: 1