I have a switch button in one cell of table view. Previously in iOS 9, everything works fine, after click switch button will goto the action method.But after update to iOS 10, the action method never be called. Anyone has similar issue like this?
cell.m
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectZero];
[bgView setImage:[[UIImage imageNamed:@"customcell.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
[self setBackgroundView:bgView];
UIImageView *selectedBgView = [[UIImageView alloc] initWithFrame:CGRectZero];
[selectedBgView setImage:[[UIImage imageNamed:@"cellselect.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
[self setSelectedBackgroundView:selectedBgView];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 13, 250, 40)];
[nameLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleRightMargin];
[nameLabel setFont:[UIFont boldSystemFontOfSize:16]];
[nameLabel setBackgroundColor:[UIColor clearColor]];
[nameLabel setTextColor:[UIColor whiteColor]];
[nameLabel setNumberOfLines:0];
[self.contentView addSubview:nameLabel];
switchButton = [[UISwitch alloc] initWithFrame: CGRectMake(230, 17, 100, 30)];
[switchButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[switchButton addTarget:self action:@selector(switchActivated:) forControlEvents:UIControlEventTouchUpInside];
[switchButton setHidden:YES];
[self.contentView addSubview:switchButton];
}
return self;
}
Action method:
- (void) switchActivated:(id)sender
{
if(switchButton.on)
{
[selectedItem setObject:@"YES" forKey:@"valueEntry"];
}
else
{
[selectedItem setObject:@"NO" forKey:@"valueEntry"];
}
}
ViewController.m cell for row at index path:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCell *tableViewCell = [aTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"homeReportCustomizationCell_%d",indexPath.row]];
if(!tableViewCell)
{
tableViewCell = [[Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Cell_%d",indexPath.row]];
}
...........
}