ios controls cell hide and display through Switch

//return 2 rows


if (indexPath.section ==6) {

   if (indexPath.row ==1) {

            [cell addSubview:self.homeView];

 

        }

        

}


//return cell height

    if (indexPath.section ==6 && indexPath.row ==1) {


       return  self.switchButton1.isOn ? 50:0;

    }





-(UISwitch *)switchButton1{

    if (!_switchButton1) {

        

        _switchButton1 = [[UISwitch alloc] init];

        _switchButton1 . onTintColor = BaseRedColor ; //The color of the left side when the switch state is on

        [_switchButton1setOn:NO];

        [_switchButton1 addTarget:self action:@selector(switch1Change:) forControlEvents:UIControlEventValueChanged];

        

    }

    return _switchButton1;

}


-(void)switch1Change:(id)sender

{

    

//    UITableViewCell *cell =(UITableViewCell*)[sender superview];

//    NSIndexPath* index=[self.tableView indexPathForCell:cell];

//    NSLog(@" section-------%ld     row--------%ld ",(long)index.section,(long)index.row );

    

  

    UISwitch *mySwitch = (UISwitch *)sender;

    if (mySwitch.isOn)

    {

        NSLog ( @"Switch 1 is on" );

        

        _homeView.hidden = NO;

        

    }

    else

    {

        NSLog ( @"Switch 1 is off" );

        

        _homeView.hidden = YES;

    }

    

   

   [self.tableView reloadData];

    


   

    

    

}







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325405862&siteId=291194637