2011-12-26 7 views
7

Así que cuando un usuario toca una celda en mi tabla, en realidad no presiono un nuevo controlador de vista. Simplemente recargo los datos dentro de ese tableView.Recargar la animación de tabla

Sin embargo, quiero obtener un efecto similar al que tendría si presionara un nuevo controlador de vista.

¿Alguien sabe cómo puedo sacar contenido viejo de la pantalla y contenido nuevo en la pantalla para una mesa entera?

Respuesta

13

Dependiendo del número de secciones que tiene puede utilizar - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

Por lo que podría hacer algo como esto:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    [tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,[self numberOfSectionsInTableView])] withRowAnimation:UITableViewRowAnimationRight]; 
} 
+0

Eres el hombre. No se ve perfecto, pero jugaré con eso. – endy

+0

¿Qué tiene de malo? – DanZimm

+1

La aplicación se bloquea si cargo datos con una cantidad diferente de secciones. Creo que voy a insertar una segunda tabla y deslizarla sobre la anterior. – endy

0

animación simple

func animateTable() { 
    self.reloadData() 

    let cells = self.visibleCells 
    let tableHeight: CGFloat = self.bounds.size.height 

    for i in cells { 
     let cell: UITableViewCell = i as UITableViewCell 
     cell.transform = CGAffineTransform(translationX: 0, y: tableHeight) 
    } 

    var index = 0 

    for a in cells { 
     let cell: UITableViewCell = a as UITableViewCell 

     UIView.animate(withDuration: 1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: UIViewAnimationOptions.curveLinear, animations: { 
      cell.transform = CGAffineTransform.identity 
     }, completion: nil) 

     index += 1 
    } 
}