Насколько я помню, вы пытаетесь построить форму вопроса. Ваш дизайн может выглядеть так.
Ваша страница будет UITableViewController, который содержит, скажем, два разных типа ячеек. Ячейка A и ячейка B. B / c вы хотите иметь различное поведение и дизайн этих двух ячеек, для которых вы хотите создать подкласс UITableCellView как для ячейки A, так и для ячейки B. В этих подклассах вы будете обрабатывать поведение ячейки. С другой стороны, ваш UITableViewController будет управлять всеми ячейками вместе.
Так вот как это сделать.
Шаг первый
Сначала давайте создадим пользовательскую ячейку A (подкласс UITableViewCell)
// CustomCellA.h
#import <UIKit/UIKit.h>
@interface CustomCellA : UITableViewCell {
UILabel *name;
NSArray *dataSource
int value;
}
@property(nonatomic,retain)IBOutlet UILabel *name;
@property(nonatomic,retain)NSArray *dataSource;
@property(nonatomic,readwrite)int value;
@end
// CustomCellA.m
#import "CustomCellA.h"
@implementation CustomCellA
@synthesize name;
@synthesize dataSource;
@synthesize type;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
name = [[UILabel alloc]init];
datasource = [NSArray alloc] init];
value = -1;
}
return self;
}
- (void)dealloc
{
[name release];
[dataSource release];
[super dealloc];
}
@end
Редактировать содержимое файла CustomCellA.xib.
- Изменить класс ячеек на CustomCellA.
- Дать идентификатор ячейки "CustomCellA"
Шаг второй
Создание ячейки B точно так же, как ячейка A выше
Шаг третий
Теперь в вашем UITableViewController вы можете использовать свою ячейку
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Use your dataSource example an NSArray field with questions as NSDictionary:
NSDictionary*question = [questions objectAtIndex:indexPath.row];
int questionType = [question integerForKey:@"type"];
if(questionType == 0){//cell A
static NSString *CellIdentifier = @"CustomCellA";
static NSString *CellNib = @"CustomCellA";
UserCustomTableCell *cell = (CustomCellA *)[table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
cell = (CustomCellA *)[nib objectAtIndex:0];
}
// setup your cell
}else{
//Do the same for cell B
}
return cell;
}