I have the following code:
+ (UITableViewCell *) createTableViewCell: (NSString *) cell_id withTableView: tableView {
SomeViewClass *cell = (SomeViewClass *)[tableView dequeueReusableCellWithIdentifier: cell_id];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed: @"AViewCell"
owner: nil
options: nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass: [UITableViewCell class]]) {
cell = (SomeViewClass *) currentObject;
break;
}
}
}
return cell;
}
I'd like to abstract that code so that it can be used with any view class, not just a "SomeViewClass". I'd like to transform it into something like the following. Notice the cast of the dynamic type (a class *) below.
+ (UITableViewCell *) createTableViewCell: (NSString *) cell_id withTableView: tableView withClass: (Class) a_class {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cell_id];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed: @"AViewCell"
owner: nil
options: nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass: [UITableViewCell class]]) {
cell = (a_class *) currentObject;
break;
}
}
}
return cell;
}
That raises a compile time error. Do I have to resort to macros? Is there a better way to do this?