I have created blur view in view controller and added sub view of custom table view cell. The problem is if I select 1st cell, it works perfectly. But if I select 2nd cell, blur view is shown in 3rd cell. If I select 3rd cell, blur view is shown in 5th cell.
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TableViewCell"];
cell = [TableViewCell new];
[self resetBoolArray];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
cell = (TableViewCell *) [self.tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
self.effectView.frame = cell.frame;
[self.effectView setHidden:[[self.boolAry objectAtIndex:indexPath.row] boolValue]];
[cell addSubview:self.effectView];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self resetBoolArray:indexPath.row];
[self.tableView reloadData];
NSLog(@"selected indexpath %ld",indexPath.row);
}
- (void)resetBoolArray {
self.boolAry = [NSMutableArray new];
for (int i = 0; i < 6; i++) {
[self.boolAry addObject:[NSNumber numberWithBool:YES]];
}
}
- (void)resetBoolArray: (NSInteger)indexpath {
self.boolAry = [NSMutableArray new];
for (int i = 0; i < 6; i++) {
if(i == indexpath) {
[self.boolAry addObject:[NSNumber numberWithBool:NO]];}
else{
[self.boolAry addObject:[NSNumber numberWithBool:YES]];}
}
}