ios 通过Switch 控制cell隐藏与显示

//返回2行


if (indexPath.section ==6) {

   if (indexPath.row ==1) {

            [cell addSubview:self.homeView];

 

        }

        

}


//返回cell高度

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


       return  self.switchButton1.isOn ? 50:0;

    }





-(UISwitch *)switchButton1{

    if (!_switchButton1) {

        

        _switchButton1 = [[UISwitch alloc] init];

        _switchButton1.onTintColor = BaseRedColor; //开关状态为开的时候左侧颜色

        [_switchButton1 setOn: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(@"开关1开启");

        

        _homeView.hidden = NO;

        

    }

    else

    {

        NSLog(@"开关1关闭");

        

        _homeView.hidden = YES;

    }

    

   

   [self.tableView reloadData];

    


   

    

    

}







猜你喜欢

转载自blog.csdn.net/iotjin/article/details/80163664
今日推荐