UISwitch 监听响应


    UISwitch *swh = [[UISwitch alloc]initWithFrame:CGRectMake(100,100, 50, 30)];
        swh.on = YES;
        [swh addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        cell.accessoryView = swh;
        cell.textLabel.text = tableArr[indexPath.section];

//switch事件方法
-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL btnSwh = [switchButton isOn];

    if (btnSwh) {
        UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"提示"
                                                                                  message: @"省流量模式已开启"
                                                                           preferredStyle:UIAlertControllerStyleAlert];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alertController animated:YES completion:nil];
    }
}

posted @ 2016-01-26 19:06  Bo-tree  阅读(613)  评论(0编辑  收藏  举报