2010-07-01 10 views

Respuesta

28

UITableView hereda de UIScrollView y desplazarse vista expone una propiedad contentOffset (documentación here).

Utilice esto con un poco de matemática para determinar si el contentOffset está dentro de frame.size.height en la parte inferior.

Actualización: he aquí una puñalada en una fórmula que le dará lo que quiere:

if(tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height)) { 
    //user has scrolled to the bottom 
} 
+0

¿Cuál es la matemática? –

+1

agregó una fórmula que puede usar ... –

+0

¡El código ya casi está allí! Puedo detectar la parte inferior, pero cuando llego al final, el código en el bloque if se llama muchas veces si el usuario mantiene la posición de desplazamiento. ¿Cómo puedo resolver? –

5

Use NSArray *paths = [tableView indexPathsForVisibleRows];. Luego, verifique si el último objeto en esa matriz es indexPath para la celda final.

Fuente: Another Question

1

Gracias a las nuevas versiones de iOS, hay una manera más fácil con la función willDisplayCell:

func tableView(tableView:UITableView, willDisplayCell cell:UITableViewCell, forRowAtIndexPath indexPath:NSIndexPath) { 

     if (indexPath.row >= tableView.numberOfRowsInSection(0)) { 

      NSLog("User got to bottom of table") 

     } 
} 

Nota que UICollectionViews tiene una función similar:

func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { 

} 
Cuestiones relacionadas