uitableviewcell example custom create ios uitableview custom-cell

ios - example - UITableViewCell. ¿Cómo acabo de resaltar la celda durante la toma de tierra?



uitableview custom cell swift 4 (5)

A continuación, el ejemplo de Swift utiliza didHighlightRowAtIndexPath para cambiar el color de fondo de la celda al tocar el didUnhighlightRowAtIndexPath contacto y didUnhighlightRowAtIndexPath para restablecer el color; consulte a continuación:

// MARK: UITableViewDelegate func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) { if let cell = tableView.cellForRowAtIndexPath(indexPath) { cell.backgroundColor = UIColor.greenColor() } } func tableView(tableView: UITableView, didUnhighlightRowAtIndexPath indexPath: NSIndexPath) { if let cell = tableView.cellForRowAtIndexPath(indexPath) { cell.backgroundColor = UIColor.blackColor() } }

Tengo un tableViewCell personalizado. Quiero indicar el toque de usuario hacia abajo resaltando. El estilo de selección de celda es UITableViewCellSelectionStyleBlue . En el controlador principal, he configurado self.clearsSelectionOnViewWillAppear = YES .

Debería ser bueno para ir No La selección sigue pegada a la celda. Lo que quiero es una indicación de selección solo durante la duración del aterrizaje. El aspecto debe volver inmediatamente al aspecto no seleccionado en el retoque.

¿Cómo hago esto?

Aclamaciones,
Doug


Esto funciona:

Obtiene la vista de fondo con el borde de la celda como separador. No cambie la configuración de la vista de tabla predeterminada en el generador de Interfaz. Asegúrese de que UITableViewCellSelectionStyleNone NO esté configurado en estilo de selección. Estoy pegando el código de trabajo. :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *kCellIdentifier = @"PlayListCell"; UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellIdentifier]; } MPMediaPlaylist *playList = [playlistCollection objectAtIndex:indexPath.row]; cell.textLabel.text = playList.name; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.detailTextLabel.text = [NSString stringWithFormat:@"%d Songs",[playList.items count]]; MPMediaItemCollection *playListMediaCollection = [playlistCollection objectAtIndex:indexPath.row ]; cell.imageView.image =[UIImage imageWithCGImage:[self getImageForCollection:playListMediaCollection.items]]; // the main code which make it highlight UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor colorWithRed:170.0f/255.0 green:170.0f/255.0 blue:170.0f/255.0 alpha:1.0f]; [bgColorView.layer setBorderColor:[UIColor blackColor].CGColor]; [bgColorView.layer setBorderWidth:1.0f]; [cell setSelectedBackgroundView:bgColorView]; return cell;

}


sobrescribir - (void)setSelected:(BOOL)selected animate:(BOOL)animated sin llamar super


Tuve el mismo problema. El siguiente código funcionó perfectamente para mí.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [[tableView cellForRowAtIndexPath:indexPath] setBackgroundColor:[UIColor blueColor]]; [table reloadData]; }


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; }