假设继承自UITableViewCell的两个类aTableViewCell和bTableViewCell。
在controller中TableVIew delegate里,cell for row的一般写法是:
static NSString abcIdentifier = @"abc";
UITableViewCell *abcCell = [TableView dequeueReusableCellWithIdentifier:abcIdentifier];
if (abcCell == nil)
{
abcCell = [[UITableViewCell alloc] init......
}
...
return abcCell;
动态写法则更灵活:如下
NSString *cellClassName = [row valueForKey:@"class"];
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:cellClassname];
if (cell == nil)
{
Class cellClass = NSClassFromString(cellClassName);
cell = [cellClass alloc];
cell = [cell initWithStyle:UITableVIewCellStyleDefault reuseIdentifier:cellClassName];
}
...
return cell;
这里
NSString *cellClassName = [row valueForKey:@"class"];