我正在尝试制作一个自定义单元格,在找到设备时生成原型单元格,这意味着每个设备都有一行。每个按钮都必须在自己的设备上起作用。自定义单元格:
我创建了一个 UITableViewCell 并声明了标签、按钮和图像。我无法让按钮在 TableViewController 上充当单独的按钮。这是 TableViewController.m
- (interruptorTableCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"dimmableCell";
interruptorTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
BinaryLight1Device *dispositivoApresentadoNaTabRetiradoDaListaDeFiltrados = [self.model.devicesFiltrados objectAtIndex:indexPath.row];
cell.accessoryView = cell.ligaDeslBtnPro;
cell.ligaDeslBtnPro.tag = indexPath.row;
[cell.ligaDeslBtnPro addTarget:self action:@selector(ligaDeslBtn:) forControlEvents:UIControlEventTouchUpInside];
cell.dimmableLabel.text = [dispositivoApresentadoNaTabRetiradoDaListaDeFiltrados friendlyName];
return cell;
}
这是在 TableView Cell 中声明的按钮操作:
- (IBAction)ligaDeslBtn:(UIButton *)sender
{
interruptorTableCell *cell = (interruptorTableCell*)[sender superview];
NSIndexPath *index=[menuView indexPathForCell:cell];
BinaryLight1Device *deviceBinaryLight = [model.devicesFiltrados objectAtIndex:sender.tag];
NSMutableString *statusDispositivos = [[NSMutableString alloc]init];
if (sender)
{
if ([statusDispositivos isEqualToString:@"0"])
{
[[deviceBinaryLight switchPower]SetarValorLigadoDesligado:@"1"];
[[deviceBinaryLight switchPower]RetornarValorLigadoDesligado:statusDispositivos];
}
else if ([statusDispositivos isEqualToString:@"1"])
{
NSLog(@"Desligando dispositivo");
[[deviceBinaryLight switchPower]SetarValorLigadoDesligado:@"0"];
[[deviceBinaryLight switchPower]RetornarValorLigadoDesligado:statusDispositivos];
}
}
我认为我的问题在于 OO,我声明它正确吗?我应该在哪里做这个?谢谢。