Вот пример пользовательской ячейки ...
.h файл
#import <UIKit/UIKit.h>
#define TAGS_TITLE_SIZE 20.0f
#define TITLE_LABEL_TAG 1
#define DATA_TIME_LABEL_TAG 5
#define ARROW_IMAGE_TAG 6
#define MAIN_IMAGE_TAG 7
#define TITLE_START_POSS 34
// Enumeration for initiakization TableView Cells
typedef enum {
NONE_TABLE_CELL = 0,
TAGS_TABLE_CELL_WITHOUT_SWITCH = 1,
TAGS_TABLE_CELL_WITH_SWITCH = 2
}TableTypeEnumeration;
@protocol SwitchDelegate
- (void)valueChangeNotify:(id)sender;
- (void)trashClickedNotify:(id)sender;
@end
// Class for Custom Table View Cell.
@interface CustomTableViewCell : UITableViewCell {
// Title of the cell.
UILabel* cellTitle;
UISwitch* cellSwitch;
UIButton* cellButton;
id<SwitchDelegate> delegate;
}
@property (nonatomic, assign) id <SwitchDelegate> delegate;
// Set the title of the cell.
- (void) SetCellTitle: (NSString*) _cellTitle;
- (void) SetRowIndex: (int) _rowIndex;
- (void) SwitchOnOff: (BOOL) _switchTo;
- (void) InitCellTitleLable;
// Init With Style (With additional parametr TableTypeEnumeration)
- (id)initWithStyle: (UITableViewCellStyle)style reuseIdentifier: (NSString *)reuseIdentifier tableType:(TableTypeEnumeration)tabletypeEnum;
@end
.m файл
#import "CustomTableViewCell.h"
@implementation CustomTableViewCell
@synthesize delegate;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//- Initializes a table-view controller to manage a table view of a given style. ----------------- ViTo Code ----//
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
return [self initWithStyle:style reuseIdentifier:reuseIdentifier tableType:NONE_TABLE_CELL];
}
- (id)initWithStyle: (UITableViewCellStyle)style reuseIdentifier: (NSString *)reuseIdentifier tableType:(TableTypeEnumeration)tabletypeEnum {
// Get Self.
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Switch table View Cells
switch(tabletypeEnum) {
case TAGS_TABLE_CELL_WITH_SWITCH: {
// Create and initialize Title of Custom Cell.
cellTitle = [[UILabel alloc] initWithFrame:CGRectMake(TITLE_START_POSS, (44 - TAGS_TITLE_SIZE)/2, 260, 21)];
cellTitle.backgroundColor = [UIColor clearColor];
cellTitle.opaque = NO;
cellTitle.textColor = [UIColor blackColor];
cellTitle.highlightedTextColor = [UIColor whiteColor];
cellTitle.font = [UIFont boldSystemFontOfSize:TAGS_TITLE_SIZE];
cellTitle.textAlignment = UITextAlignmentLeft;
// Create and Initialize Switch of Custom Cell.
cellSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(185 + TITLE_START_POSS, 10, 10, 10 )];
[cellSwitch addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
// Create and Initialize Trash Button of Custom Cell.
cellButton = [[UIButton alloc] initWithFrame:CGRectMake(1, 7, 32, 32)];
[cellButton setImage:[UIImage imageNamed:@"remove_tag.png"] forState:UIControlStateNormal];
[cellButton addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
[self.contentView addSubview:cellTitle];
[self.contentView addSubview:cellSwitch];
[self.contentView addSubview:cellButton];
[cellTitle release];
[cellSwitch release];
[cellButton release];
break;
}
case TAGS_TABLE_CELL_WITHOUT_SWITCH: {
// Create and initialize Title of Custom Cell.
cellTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, (44 - TAGS_TITLE_SIZE)/2, 260, 21)];
cellTitle.backgroundColor = [UIColor clearColor];
cellTitle.opaque = NO;
cellTitle.textColor = [UIColor blackColor];
cellTitle.highlightedTextColor = [UIColor whiteColor];
cellTitle.font = [UIFont boldSystemFontOfSize:TAGS_TITLE_SIZE];
cellTitle.textAlignment = UITextAlignmentLeft;
[self.contentView addSubview:cellTitle];
[cellTitle release];
}
default: break;
}
}
return self;
}
-(void)touchDown: (id)sender {
[delegate trashClickedNotify:sender];
}
-(void)valueChange:(id)sender {
[delegate valueChangeNotify:sender];
}
- (void) InitCellTitleLable {
cellTitle = (UILabel *)[self.contentView viewWithTag:TITLE_LABEL_TAG];
}
- (void) SetRowIndex: (int) _rowIndex {
cellSwitch.tag = _rowIndex;
cellButton.tag = _rowIndex;
}
- (void) SwitchOnOff: (BOOL) _switchTo {
cellSwitch.on = _switchTo;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//- Set title of the Cell. ----------------------------------------------------------------------- ViTo Code ----//
- (void) SetCellTitle: (NSString*) _cellTitle {
cellTitle.text = _cellTitle;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//- Deallocates the memory occupied by the receiver. --------------------------------------------- ViTo Code ----//
- (void)dealloc {
// Delloc objects.
//[self.cellMainImage release];
//[self.cellTitle release];
//[self.cellDataTime release];
// Call base delloc
[super dealloc];
}
@end