主要是通过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

}
    
}

在tableviewcell里面嵌入switch控件以及如何获取switch控件数据的更多相关文章

  1. ASP.NET MVC加载用户控件后并获取其内控件值或赋值

    有网友看了这篇<ASP.NET MVC加载ASCX之后,并为之赋值>http://www.cnblogs.com/insus/p/3643254.html 之后,问及Insus.NET,不 ...

  2. JAVA反射机制_获取字节码文件对象

    是在运行状态中,对于任意一个类 (class文件),都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性: 这种动态获取的信息以及动态调用对象的方法的功能称为java语 ...

  3. Dev控件GridView单元格绑定控件

    Dev控件GridView单元格绑定控件 //文本按钮 RepositoryItemButtonEdit btnFields = new RepositoryItemButtonEdit();//创建 ...

  4. Cocos2d-x3.0游戏实例之《别救我》第六篇——从代码中获取UI控件

    这篇的内容非常easy,获取UI控件,然后使用它. 还记得我们在UI编辑器中给三个button分别命名了吧? 如今要用上了. 笨木头花心贡献,啥?花心?不呢,是用心~ 转载请注明,原文地址: http ...

  5. UGUI 之获取当前控件的高度

    当Canvas Scaler选择Constant Pixel Size 当前的分辨率会被被固定,可以用RectTransform类里面的.rect变量值获取 height或Width. 在次情况下获取 ...

  6. winfrom获取用户控件里的控件对象

    如何获取用户控件里的控件对象呢,其实思路也是很简单的, 比如有一个panel 用户控件 里面有许多的其他控件. 那么要找出一个Label控件怎么找呢,好的.现在我们就开始 首先,一个foreach循环 ...

  7. .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】

    1.首先在前台dataGridview属性中增加onRowDataBound属性事件 2.然后在后台Observing_RowDataBound事件中增加代码 protected void Obser ...

  8. 获取android控件的高度

    问题 如何获取一个控件的长和高,相信很多朋友第一眼看见这个问题都会觉得很简单,直接在onCreate里面调用getWidth.getMeasuredWidth不就可以获得了吗,但是,事实上是并没有简单 ...

  9. .net获取select控件中的文本内容

    .net获取select控件中的文本内容 2009-11-28 21:19小V古 | 分类:C#/.NET | 浏览1374次 <select id="SecType" st ...

随机推荐

  1. Vue 中select option默认选中的处理方法

    在做泰康项目的时候有个需求就是要给select默认选中的样式我的处理方法有两个 1.直接将默认值给  selectedOption <select v-model="selectedO ...

  2. Error:svn: E160013 svn主干切换分支时报错

    Error:svn: E160013: û���ҵ��ļ�: �汾��10574����·�� ��/aap/branches/20180613�� 前几天遇到了这个问题,心里特别崩溃,之前可以从主干 ...

  3. Using promises

    [Using promises] 过去,异步方法这样写: function successCallback(result) { console.log("It succeeded with ...

  4. excel 数据量较大边查询边输入到excel表格中

    public Resultmodel getexpenseMessagx(HttpServletResponse response, String date1, String date2) { lon ...

  5. 【Django】关于ORM的使用

    添加模型并映射到数据库中: 1. 在 settings.py 中,配置好 DATABASES ,做好数据库相关的配置. 以mysql为例: DATABASES = { 'default': { 'EN ...

  6. Python程序打包—pyinstaller

    简介:PyInstaller是一个十分有用的第三方库,通过对源文件打包,Python程序可以在没有安装 Python的环境中运行,也可以作为一个独立文件方便传递和管理. PyInstaller的官方网 ...

  7. 51nod 1459 迷宫游戏 dijkstra模板

    链接:迷宫游戏 问题 - 51Nod  http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1459 1459 迷宫游戏  基准 ...

  8. 不要62(数位DP)

    不要62 http://acm.hdu.edu.cn/showproblem.php?pid=2089 Time Limit: 1000/1000 MS (Java/Others)    Memory ...

  9. 数据库(mysql)

    一.left join  right join  inner join left join(左连接),在两张表进行连接查询时,会返回左表所有的行,即使在右表中没有匹配的记录. right join(右 ...

  10. static 构造函数的认识

    最近,看到一道面试题,如下 class Class1 { ; static Class1() { count++; } public Class1() { count++; } } Class1 on ...