UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UISwitch *clickButton = (UISwitch *)[cell viewWithTag:30];
clickButton.tag = indexPath.row;
[clickButton addTarget:self action:@selector(cellButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
UILabel *title = (UILabel*)[cell viewWithTag:80];
UILabel *description = (UILabel*)[cell viewWithTag:81];
UIView *innerView = (UIView *)[cell viewWithTag:82];
innerView.layer.borderColor=[[UIColor colorWithRed:229/255.0f green:229/255.0f blue:229/255.0f alpha:1.0] CGColor];
innerView.layer.borderWidth = 2.0f;
NSDictionary *displayDict = scenarioListsArray[indexPath.row];
title.text =[displayDict objectForKey:@"name"];
description.text = [displayDict objectForKey:@"description"];
if ([[displayDict objectForKey:@"status"] isEqualToString:@"ACTIVE"]) {
[clickButton setOn:YES animated:YES];
NSLog(@"SWITCH %ld",clickButton.tag);
}
else
{
[clickButton setOn:NO animated:YES];
}
我需要更改Switch的状态取决于数组,但是数组上的开关状态不会改变。