La mejor manera de hacerlo es agregar una celda ficticia debajo de la celda que se tocó.
Primero debe realizar un seguimiento de qué celda se ha intervenido y actuar en consecuencia.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//if user tapped the same row twice let's start getting rid of the control cell
if([indexPath isEqual:self.tappedIndexPath]){
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
//update the indexpath if needed... I explain this below
indexPath = [self modelIndexPathforIndexPath:indexPath];
//pointer to delete the control cell
NSIndexPath *indexPathToDelete = self.controlRowIndexPath;
//if in fact I tapped the same row twice lets clear our tapping trackers
if([indexPath isEqual:self.tappedIndexPath]){
self.tappedIndexPath = nil;
self.controlRowIndexPath = nil;
}
//otherwise let's update them appropriately
else{
self.tappedIndexPath = indexPath; //the row the user just tapped.
//Now I set the location of where I need to add the dummy cell
self.controlRowIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
}
//all logic is done, lets start updating the table
[tableView beginUpdates];
//lets delete the control cell, either the user tapped the same row twice or tapped another row
if(indexPathToDelete){
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToDelete]
withRowAnimation:UITableViewRowAnimationNone];
}
//lets add the new control cell in the right place
if(self.controlRowIndexPath){
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:self.controlRowIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
//and we are done...
[tableView endUpdates];
}
cada vez que tenga esa célula ficticia presente usted tiene que asegurarse de que envíe la cuenta correcta.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(self.controlRowIndexPath){
return modelArray.count + 1;
}
return self.modelArray.count;
}
Además, devolver la altura apropiada para su ControlCell.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([indexPath isEqual:self.controlRowIndexPath]){
return 45; //height for control cell
}
return 70; //height for every other cell
}
Por último, recordar la célula de control es un maniquí. No es parte del modelo, por lo tanto, tienes que dar cuenta de eso. Si el usuario toca una fila que está encima, la última fila girada está bien, pero cuando la nueva fila golpeada está debajo de esa celda de control, debe asegurarse de acceder a la fila derecha de su modelo. En otras palabras, cuenta para esa celda falsa en el medio de tu vista.
- (NSIndexPath *)modelIndexPathforIndexPath:(NSIndexPath *)indexPath
{
int whereIsTheControlRow = self.controlRowIndexPath.row;
if(self.controlRowIndexPath != nil && indexPath.row > whereIsTheControlRow)
return [NSIndexPath indexPathForRow:indexPath.row - 1 inSection:0];
return indexPath;
}
Espero que esto ayude.
Creo que este es un mejor diseño que la mención donde se debe cambiar el origen de datos. – Gary
así que básicamente va a añadir un nuevo punto de vista aquí en este lugar de una nueva fuente de datos, esto es lo que tenía en mente inicialmente .. algo más de código sería genial ... basado en mi entendimiento va a añadir esta vista para cada celular en la mesa? – aherlambang
Crearía una vista y la eliminaría de la celda seleccionada anterior cada vez antes de agregarla a la nueva celda. –