2011-02-10 9 views
6

Tengo un NSTableView, y me gustaría saber cuándo se ha desplazado hacia abajo para poder realizar una acción. ¿No estoy seguro de cómo hacerlo?Cómo determinar si un usuario se desplazó hasta el final de un NSTableView

ACTUALIZACIÓN: Así es como estoy calculando la parte inferior de la tabla:

-(void)tableViewDidScroll:(CPNotification) notification 
{ 
    var scrollView = [notification object]; 
    var currentPosition = CGRectGetMaxY([scrollView visibleRect]); 
    var tableViewHeight = [messagesTableView bounds].size.height - 100; 

    //console.log("TableView Height: " + tableViewHeight); 
    //console.log("Current Position: " + currentPosition); 

    if (currentPosition > tableViewHeight - 100) 
    { 
     console.log("we're at the bottom!"); 
    } 
} 

Respuesta

14

puede agregarse como observador (en el sentido NSNotificationCenter, no el sentido de MVA/Vinculaciones) de NSViewBoundsDidChangeNotification de la table -conclosingScrollView's -contentVer y reaccionar según sea necesario en función del rectángulo visible.

actualización

hacer esto en alguna parte (tal vez -awakeFromNib):

// Configure the scroll view to send frame change notifications 
id clipView = [[tableView enclosingScrollView] contentView]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(myBoundsChangeNotificationHandler:) 
              name:NSViewBoundsDidChangeNotification 
              object:clipView]; 

poner esto en alguna parte útil:

- (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification 
{ 

if ([aNotification object] == [[tableView enclosingScrollView] contentView]) 
    [self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe]; 

} 

Esencialmente desea examinar de la vista de desplazamiento -documentVisibleRect para ver si tal vez el par de píxeles inferior es visible. Recuerde tener en cuenta la posibilidad de vistas con sistemas de coordenadas volteadas - "vistas volteadas" - cubiertas en el Views Programming Guide.

+0

puedo mostrar un fragmento? –

+0

He actualizado la publicación. –

+0

Esto funciona bien, ¿me pueden ayudar un poco al calcular si los píxeles inferiores son visibles? –

0

En cuanto a su actualización: por alguna razón tengo var currentPosition = CGRectGetMaxY ([scrollView visibleRect]); siempre el mismo valor, he encontrado mejor usar NSClipView límites:

NSClipView *clipView = ...; 
NSRect newClipBounds = [clipView bounds]; 
CGFloat currentPosition = newClipBounds.origin.y + newClipBounds.size.height; 
Cuestiones relacionadas