我的应用程序导航和视图是UITableviewController。我需要为特定的UIViewtable单元添加ON和OFF的开关控制。如何添加。
答案 0 :(得分:3)
这也是一个经典之作,这个问题已经在这里问了很多。例如,请参阅this question。搜索UITableView
和UISwitch
以获得更多结果。
答案 1 :(得分:3)
您可以使用UITableViewDataSource
Protocol
-tableView:cellForRowAtIndexPath:
方法添加切换
- (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;
}