ios iphone uitableview uibutton uiswitch

ios - UISwitch y UIButton en UITableViewCell, cómo identificarlos



iphone (1)

Tengo un pequeño problema en mi UITableViewCell. Cada celda personalizada tiene un UISwitch y un UIButton. Y cuando el usuario cambie el valor de UISwitch, me gustaría establecer la propiedad button.hidden en YES.

Puedo encontrar con qué UISwitch se hizo clic con este método:

- (IBAction)closeHour:(id)sender { UISwitch *senderSwitch = (UISwitch *)sender; UITableViewCell *switchCell = (UITableViewCell *)[senderSwitch superview]; NSUInteger buttonRow = [[resas indexPathForCell:switchCell] row]; NSLog("%d", buttonRow); }

Esto funciona perfectamente, pero no sé cómo hacer que UIButton esté en el mismo índice (indexPath.row) para establecer su propiedad oculta. Pensé en poner una etiqueta en cada UIButton pero no soy muy amigable con ellos.

Así es como se creó mi Célula, si alguien puede decirme que si estoy haciendo una mierda aquí, podría ser muy agradable:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier1 = @"Cell1"; static NSString *cellIdentifier2 = @"Cell2"; if ([typeOfData objectAtIndex:indexPath.row] == @"hour") { TimeCell *cell = (TimeCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1]; if (cell == nil) { cell = [[[TimeCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier1] autorelease]; UISwitch *isOpen = [[UISwitch alloc] initWithFrame:CGRectMake(300, 7, 0, 0)]; if ([self openOrCloseHour:[[[finalData objectAtIndex:indexPath.row] substringToIndex:2] intValue]]) isOpen.on = YES; else { isOpen.on = NO; [isOpen addTarget:self action:@selector(closeHour:) forControlEvents:UIControlEventValueChanged]; [cell addSubview:isOpen]; [isOpen release]; UIButton *add = [UIButton buttonWithType:UIButtonTypeContactAdd]; add.frame = CGRectMake(400, 3, 170, 40); [add addTarget:self action:@selector(addResa:) forControlEvents:UIControlEventTouchDown]; [cell addSubview:add]; } } [cell.time setText:[finalData objectAtIndex:indexPath.row]]; return cell; } else { ResaCell *cell = (ResaCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2]; if (cell == nil) { cell = [[[ResaCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier2] autorelease]; [cell.isConfirm setImage:[UIImage imageNamed:@"confirm.png"]]; [cell.nom setText:[finalData objectAtIndex:indexPath.row]]; [cell.prenom setText:[finalData objectAtIndex:indexPath.row]]; [cell.arrive setText:[finalData objectAtIndex:indexPath.row]]; } return cell; } return nil; }

Para obtener información, tengo dos tipos de células. El problema está en TimeCell.

¿Alguien tiene la solución?


En el cellForRow:

isOpen.tag = 2000+indexPath.row; add.tag = 4000+indexPath.row;

Para obtener el UIButton en el cierreHour IBACtion make:

int tagButton = senderSwitch.tag-2000+4000; button = (UIButton*)[self.view viewWithTag:tagButton];