I have a question …
I have Custom TableViewCell class:
// Class for Custom Table View Cell.
@interface CustomTableViewCell : UITableViewCell {
// Title of the cell.
UILabel* cellTitle;
// Switch of the cell.
UISwitch* cellSwitch;
}
How you can see in my custom UITableViewCell I have Label and Switch controller.
- (id)initWithStyle: (UITableViewCellStyle)style reuseIdentifier: (NSString *)reuseIdentifier tableType:(TableTypeEnumeration)tabletypeEnum {
// Get Self.
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// 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;
// Create and Initialize Switch of Custom Cell.
cellSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(185, 10, 10, 10 )];
[self.contentView addSubview:cellTitle];
[self.contentView addSubview:cellSwitch];
[cellTitle release];
[cellSwitch release];
}
return self;
}
Now when I use my custom cell in TableView I want to catch event when user change the state of switch. How can I do that ?
You have to write method for value change as below:
Then you have to implement delegate
then you have to make object id delegate and synthesis with (nonatomic, assign) propertly and method as below:
By this way, you can get notify state change in view controller.