-1
我正在尝试制作自定义单元格,因为它发现设备时生成了原型单元格,这意味着每个设备都有一行。每个按钮都必须在自己的设备上运行。定制单元格:每个单元格的单独按钮,创建为设备时创建的
我创建了一个UITableViewCell并声明了标签,按钮和图像。我无法使按钮充当在TableViewController.Here各个按钮是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中细胞声明:
- (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];
}
}
我想我的问题是面向对象,我宣称它是正确的?我应该在哪里做这个? 谢谢。