2010-12-15 68 views
1

我的应用程序导航和视图是UITableviewController。我需要为特定的UIViewtable单元添加ON和OFF开关控制。如何添加。如何在tableview单元格中添加切换

+0

可能重复发现-tableView:cellForRowAtIndexPath:方法(http://stackoverflow.com/questions/3770019/uiswitch-in-添加一个开关a-uitableview-cell) – Mac 2012-05-17 02:19:46

回答

3

也是一个经典,这个问题已经在这里问了很多。例如,请参阅this question。搜索UITableViewUISwitch以获得更多结果。

+0

感谢您的示例以获得我的解决方案 – SOF 2010-12-15 17:08:45

3

你可以在[在一个UITableView细胞UISwitch]在的UITableViewDataSource Protocol

- (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]; 
    } 

    // Configure the cell... 
    UISwitch *aSwitch = [[[UISwitch alloc] init] autorelease]; 
    [aSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; 
    [cell.contentView addSubview:aSwitch]; 
    return cell; 
} 
+0

感谢您解释添加开关控制器。 – SOF 2010-12-15 17:09:15

相关问题