主要是通过cell.accessoryView来添加switch控件
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    //add a switch
    UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchview addTarget:self action:@selector(updateSwitchAtIndexPath:) forControlEvents:UIControlEventValueChanged];
    cell.accessoryView = switchview;
    [switchview release];
}

cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];

return cell;
}

.h文件中添加:
- (IBAction) updateSwitchAtIndexPath:(id) sender;

获取switch数据:
- (IBAction)updateSwitchAtIndexPath:(id)sender {
    
    
    UISwitch *switchView = (UISwitch *)sender;
    
    if ([switchView isOn]) 
{
       //do something..     

else 
{
    //do something

}
    
}

最新文章

  1. 2-st学习笔记
  2. 读>>>>白帽子讲Web安全<<<<摘要→我推荐的一本书→1
  3. Angularjs 如何在 post 请求时去掉因 ng-repeat 产生的 $$hashkey?
  4. BIOS 深入学习 转
  5. Struts2+hibernate3+Spring2的整合方法
  6. ethtool 在 Linux 中的实现框架和应用
  7. POJ3666-Making the Grade(左偏树 or DP)
  8. 实现ios屏幕的横竖屏自适应
  9. Map的遍历方法及String和其它类型的相互转化
  10. NSString、NSData、char* 类型之间的转换-备
  11. JPA 系列教程1-环境搭建
  12. html中DTD
  13. 浏览器之window对象--javascript
  14. Node.js NPM 使用介绍
  15. python 3.6 lxml标准库lxml的安装及etree的使用注意
  16. 1-VScode格式化ESlint-方法(最全最好用方法!)
  17. (1.13)mysql优化数据库对象
  18. IDEA引入Gradle工程小记
  19. 非极大值抑制(NMS)
  20. # rp2833板卡更新u-boot.bin的步骤

热门文章

  1. Linux初学时的一些常用命令(1)
  2. yii2.0 手动配置redis
  3. php loop循环 拿到键名
  4. JS的6种常见继承模式
  5. linux下的ping工具--fping
  6. TOJ3216 我要4444
  7. 152. Maximum Product Subarray (Array; DP)
  8. oracle数据库导入导出问题
  9. 【python】入门指南:控制语句
  10. f5 Seldom used