2010-09-08 60 views
11

Hace algún tiempo, alguien ya hizo esta pregunta y se dieron algunas respuestas, pero realmente no entendí ninguna de ellas. Así que me preguntaba si alguien podría por favor escriba un fácil entender tutorial sobre cómo hacer las cosas que aparecen en la imagen de abajo:¿Cómo agregar casillas de verificación a UITableViewCell?

http://img208.yfrog.com/img208/6119/screenshotkmr.png

Yo estaría muy agradecido si alguien puede compartir exactamente cómo esto porque se ve muy bien y me encantaría usar algo similar en mi aplicación :-)!

+0

leer este enlace http://walkingsmarts.com/creating-radio-button-and -checkbox-lists-using-uitableview/puede ayudarlo –

Respuesta

30

hacer una imagen sin control y comprobado ..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if ([selectedRowsArray containsObject:[contentArray objectAtIndex:indexPath.row]]) { 
     cell.imageView.image = [UIImage imageNamed:@"checked.png"]; 
    } 
    else { 
     cell.imageView.image = [UIImage imageNamed:@"unchecked.png"]; 
    } 
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleChecking:)]; 
    [cell.imageView addGestureRecognizer:tap]; 
    cell.imageView.userInteractionEnabled = YES; //added based on @John 's comment 
    //[tap release]; 

    cell.textLabel.text = [contentArray objectAtIndex:indexPath.row]; 
    return cell; 
} 

- (void) handleChecking:(UITapGestureRecognizer *)tapRecognizer { 
    CGPoint tapLocation = [tapRecognizer locationInView:self.tableView]; 
    NSIndexPath *tappedIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation]; 

    if ([selectedRowsArray containsObject:[contentArray objectAtIndex:tappedIndexPath.row]]) { 
     [selectedRowsArray removeObject:[contentArray objectAtIndex:tappedIndexPath.row]]; 
    } 
    else { 
     [selectedRowsArray addObject:[contentArray objectAtIndex:tappedIndexPath.row]]; 
    } 
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:tappedIndexPath] withRowAnimation: UITableViewRowAnimationFade]; 
} 
+0

indexForRowAtPoint no es un programa de acceso reconocido en UITableView ... ¿cómo lo hago para que funcione? – quantum

+0

Lo sentimos, debería ser indexPathForRowAtPoint: .. El código ahora se ha corregido – LarsJK

+0

hm todavía no parece reconocer ningún toque específico en el cell.imageView. ¿algunas ideas? – quantum

1

Una de las maneras en que puedo pensar es que usted hace la UITableViewCell personalizada (this tutorial es buena para comenzar. Esto es another, similar one). Dentro de la UITableViewCell personalizada, debes poner un UIButton allí con una imagen circular. Cuando el usuario selecciona el botón, se cambia de canal para el círculo verde

Cuestiones relacionadas