-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];
}
}
我想我的問題是面向對象,我宣稱它是正確的?我應該在哪裏做這個? 謝謝。