Evite el cambio de tamaño automático de la vista de contenido de celda de uitableview al ingresar al modo de edición

I have a uitableviewcell with content view containing some custom view.' When the table view enters edit mode the content view resizes (becomes narrower) there by the image in the content view is shrunk horizontally

Does anyone know how to prevent this ?

I have set the cell indentation to none.

Muchas Gracias

preguntado el 12 de junio de 12 a las 22:06

4 Respuestas

Has intentado configurar shouldIndentWhileEditing a NO

Take a look at properties :


Respondido el 12 de junio de 12 a las 23:06

I forgot to mention, I have implemented that already & it does not make any difference. - kukushkin

Have you tried setting the auto-resize masks on the view?

theView.autoresizingMask = UIViewAutoresizingNone;

You may need to set it on the content view and/or the image view - it's not clear exactly how your view hierarchy is structured. However, the frame might be set explicitly (rather than auto-resized) by the framework, in which case this won't work.

If you are trying to have a background image for the entire table cell, you may also want to try an alternative method which is to set the backgroundColor of the cell like this:

UIImage* someImage = [UIImage imageNamed:@"someImage"];
cell.backgroundColor = [UIColor colorWithPatternImage:someImage];

Remember to make sure the backgroundColor of all other views you place inside are [UIColor clearColor] so that you can see through to the background image.

Respondido el 12 de junio de 12 a las 23:06

nope that dint work either, the frame and bounds of the content view change (width reduces) when I enter edit mode. - kukushkin

Siempre puede obtener una celda de vista de tabla con una ruta de índice. Usando ese identificador de reutilización de celda de vista de tabla, puede evitar que el tamaño del contenido de la celda de vista de tabla cambie de tamaño o no. Tenía el requisito de implementar un tipo similar de funcionalidad para evitar el cambio de tamaño de celdas separadas. PFB el código.

-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{

BOOL shouldIndentWhileEditingRow = NO;

UITableViewCell *lTableViewCell = [tableView cellForRowAtIndexPath:indexPath];

/*Change the position of the target rect based on Sending messages or Receiving messages*/
if ([lTableViewCell.reuseIdentifier isEqualToString:@"SendingChatCellIdentifier"]) {

    shouldIndentWhileEditingRow = NO;

}else if ([lTableViewCell.reuseIdentifier isEqualToString:@"ReceivingChatCellIdentifier"]){

    shouldIndentWhileEditingRow = YES;

return shouldIndentWhileEditingRow;

respondido 26 nov., 15:15

I did something similar to avoid the cell content to be resized when using cell automatic dimension.

My problem was that the textView inside the cell, after the selection, was wrapping its content in more lines, and I just wanted to avoid this.

To solve this "issue":

  • I added a trailing constraint of 40px (the size of the accessory view) to the cell content
  • On cell select, i change the constraint to 0, so the text is 40 px larger, but as the accessory shows up, you don't see any changes.

The pro of this solution is that the content dimension is not changing anymore when user select a row. the con is that you have always 40px of free space on the right of the cell, also when not selected.

Respondido 09 ago 19, 11:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.