我有一个带有开关控制的表格视图。我的问题是:单击开关时如何检索行表ID?我可以检索开关状态,但不能检索 id
这是我获取开关状态的代码:
- (void)aggiungiTag:(id)sender {
NSLog(@"the tag value is: %d", [sender isOn]);
return;
}
这是我将按钮开关控制到单元格的代码:
- (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];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Configure the cell...
//inseriamo nelle celle la nostra lista
cell.textLabel.text = [arrTagResidui objectAtIndex:indexPath.row];
/*** aggiungo lo switch per i tag ***/
//lo istanzio e setto la posizione
UISwitch *switchObj = [[UISwitch alloc] initWithFrame:CGRectMake(1.0, 1.0, 20.0, 20.0)];
//setto il valore di default
switchObj.on = NO;
//setto l'action ed i controlli degli eventi
[switchObj addTarget:self action:@selector(aggiungiTag:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
//aggiungo lo switch alle celle
cell.accessoryView = switchObj;
NSInteger row = indexPath.row;
[arrBoolSwitch insertObject:[NSNumber numberWithBool:NO] atIndex:row];
[switchObj release];
return cell;
}