我有一个有四行的表。其中两个应显示在最初 - 第1行和第2行。另外两个应该只在位于第2行的UISwitch
的状态为“On”时出现。如果状态设置为“关”,则它们应该消失。根据UISwitch的状态删除或添加UITableViewCell
我已经创建了持有UISwitch
一个UITableViewCell
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSMutableArray *dict = [dictionary objectForKey:@"DATA"];
//the location of the switch!
if(indexPath.row == 1){
SwitchCell *cell = (SwitchCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SwitchCell" owner:self options:nil];
cell = (SwitchCell *)[nib objectAtIndex:0];
}
cell.title1.text = [dict objectAtIndex:indexPath.row];
[cell.switchSpecifyEnd addTarget:self action:@selector(switchSpecifyEnd) forControlEvents:UIControlEventValueChanged];
mySwitch = cell.switchSpecifyEnd;
return cell;
}else{
static NSString *CellIdentifier1 = @"CustonCell";
DateTimeCell *cell = (DateTimeCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DateTimeCell" owner:self options:nil];
cell = (DateTimeCell *)[nib objectAtIndex:0];
}
cell.description.text = [dict objectAtIndex:indexPath.row];
cell.dateTime.text = self.date;
return cell;
}
}
-(void) switchSpecifyEnd{
//displays only 0 (defined initial state of my switch)
NSLog(@"SWITCH - Specify End: %d", mySwitch.state);
// [tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
// [tableView1 reloadData];
}
我怎样才能行3和4,开始时不显示,并让如果开关的状态更改为“开”他们出现在哪里?