En mi UITableView
, cuando ingresa al modo de edición, solo me gustaría seleccionar unas pocas celdas. Sé que la clase UITableView
tiene la propiedad allowsSelectionDuringEditing
, pero esto se aplica a todo UITableView
. No veo ningún método delegado relevante para configurar esto por celda.UITableView modo de selección por celda durante la edición
La mejor solución que se me ocurre es establecer allowsSelectionDuringEditing
en YES
. Luego, en didSelectRowAtIndexPath
, filtre las selecciones no deseadas si la vista de tabla está editando. Además, en cellForRowAtIndexPath
, cambie esas celdas selectionStyle
a Ninguna.
El problema con esto es que pasar al modo de edición no recarga el UITableViewCells
, por lo que su selectionStyle
no cambia hasta que se desplazan fuera de la pantalla. Entonces, en setEditing, también tengo que iterar sobre las celdas visibles y establecer su selectionStyle
.
Esto funciona, pero me pregunto si hay una solución mejor/más elegante para este problema. El esquema básico de mi código está adjunto. ¡Cualquier sugerencia muy apreciada! Gracias.
- (void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
if (self.editing && ![self _isUtilityRow:indexPath]) return;
// Otherwise, do the normal thing...
}
- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
// UITableViewCell* cell = ...
if (self.editing && ![self _isUtilityRow:indexPath])
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
return cell;
}
- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing)
{
for (UITableViewCell* cell in [self.tableView visibleCells])
{
if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
}
else
{
for (UITableViewCell* cell in [self.tableView visibleCells])
{
if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
}
}
}
Puede volver a cargar la tabla cuando entra en modo de edición, o anular la selección tan pronto como se seleccione en lugar de establecer el estilo de selección en ninguno ... – AMayes