文章来源:http://stackoverflow.com/questions/3770019/uiswitch-in-a-uitableview-cell
Setting it as the accessoryView is usually the way to go. You can set it up intableView:cellForRowAtIndexPath:
You may want to use target/action to so something when the switch is flipped. Like so:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { switch( [indexPath row] ) { case MY_SWITCH_CELL: { UITableViewCell* aCell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"]; if( aCell == nil ) { aCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SwitchCell"] autorelease]; aCell.textLabel.text = @"I Have A Switch"; aCell.selectionStyle = UITableViewCellSelectionStyleNone; UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; aCell.accessoryView = switchView; [switchView setOn:NO animated:NO]; [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; [switchView release]; } return aCell; } break; } return nil; } - (void) switchChanged:(id)sender { UISwitch* switchControl = sender; NSLog( @"The switch is %@", switchControl.on ? @"ON" : @"OFF" ); }
相关推荐
iOS UISwitch 详细使用说明文档
自定义SwitchButton实现IOS中的UISwitch动画效果
IOS编写UISwitch的自定义,有图片自定义,显示动态效果
自定义UISwitch,方便大家使用
ITSwitch 是 Mac OS X 上 UISwitch 的替代品。 标签:ITSwitch
主要介绍了iOS开发中UISwitch按钮的使用方法,代码基于传统的Objective-C,需要的朋友可以参考下
一、第一种创建UISwitch组件的方法,在代码中动态创建。 1、打开Xcode, 新建项目Switch,选择Single View Application。 2、打开ViewController.m文件在viewDidLoad方法里添加代码: 代码如下: (void)viewDidLoad ...
Switch.js是一款可以将任意CheckBox控件转换为iOS样式滑动开关按钮的JS插件。Switch.js使用简单,功能强大,它可以控制滑动按钮的尺寸,颜色,状态等。
这篇博客http://blog.csdn.net/qq_15509071/article/details/78639187 ”如何更改工程内最少的代码修改系统UISwitch的大小和样式 “的示例代码
主要为大家详细介绍了iOS通过UISwitch控制摇一摇,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
SevenSwitch, 在UISwitch的替换中,ios样式除去 SevenSwitchweb ios样式在UISwitch中的替换 用法 Cocoapodspod 'SevenSwitch', '~> 2.1'Swift 支持在版本 2.0 中添加。 如果
UISwitch 控件 ZJSwitch ,ZJSwitch 实现具有 iOS7 风格 UISwitch 控件,可在Switch上显示定制文字。...
纯js写的一个switch开关(或叫checkbox开关)
自定义 UISwitch
主要介绍了Android UI设计系列之自定义SwitchButton开关实现类似IOS中UISwitch的动画效果,具有一定的实用性和参考价值,感兴趣的小伙伴们可以参考一下
DYSwitchXDemo 类似 iOS UISwitch 用于 Mac OS X。
iphone中的基础控件UISwitch,适合初学者,主要学习UISwitch的常用属性设置、点击事件、以及改变开关的lable等,UISwitch包含一个UISwitchSlider子视图,此UISwitchSlider包含3个UIImageView和1个UIView(就是显示开...
包含collectionView,UIBezierPath,ActionSheet,DatePicker,pickerView,SearchBar,UIActivityIndicatorView,UIAlertView,UIButton,...UISwitch,UITabarController,UItableView,UItextView,UIWebView,动画的基础应用