In #50: UITableView -registerClass:forCellReuseIdentifier:, I wrote about using UITableView
-registerClass:forCellReuseIdentifier:
. But if you use UITableView
, you wouldn't be able to use any style other than UITableViewCellStyleDefault
. The only way to work around it is to implement a subclass for each style you want to use and pass them to -registerClass:forCellReuseIdentifier:
instead. E.g. to use UITableViewCell
with UITableViewCellStyleSubtitle
, do this:
@interface TableViewCellStyleSubtitle : UITableViewCell
@end
@implementation TableViewCellStyleSubtitle
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier {
//Hardcoded to UITableViewCellStyleSubtitle
if (self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]) {
}
return self;
}
@end
and then use it like this:
[self.tableView registerClass:[TableViewCellStyleSubtitle class] forCellReuseIdentifier:@"Some Identifier"];
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.