0

I populated my NStableView with tableView Controller and it's working fine. I only want to know why every time I am getting the data (Presented in table Cell) whenever the user hovers on a particular cell in a tableview, it starts displaying the data in console.

I found that this - (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row calls every time and I stack traced using instruments and this method is taking a lot of memory.

Is there any way to stop this method drawing the data every time.

A--C
  • 36,351
  • 10
  • 106
  • 92
york
  • 149
  • 1
  • 11

1 Answers1

0

Add the delegate -viewWillMoveToWindow to the view subclass contain the table. here i have used the BOOL named reloadTable. NSTrackingArea is the answer for your problem

- (void) viewWillMoveToWindow:(NSWindow *)newWindow
{
    // Setup a new tracking area when the view is added to the window.
    NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[yourTable frame]
                options: (NSTrackingMouseEnteredAndExited |  
                NSTrackingActiveAlways|NSTrackingEnabledDuringMouseDrag) owner:self userInfo:nil];
    [self addTrackingArea:trackingArea];

}

- (void) mouseEntered:(NSEvent*)theEvent {
    reloadTable=YES;
    NSLog(@"enter %@",theEvent);

}

- (void) mouseExited:(NSEvent*)theEvent {

     reloadTable=YES;

}

then use it in your NSTableViewDataSource methods

vignesh kumar
  • 2,310
  • 2
  • 25
  • 39
  • I am getting an error in [self addTrackingArea:trackingArea]; should i use [tableView addTrackingArea:trackingArea]; ? – york Nov 21 '12 at 05:38
  • viewWillMoveToWindow is not calling, i have used NSViewController to display the views. – york Nov 21 '12 at 05:49
  • sorry bro the viewWillMoveToWindow is an NSView method all the above method has to be implemented in NSView subclass – vignesh kumar Nov 21 '12 at 05:55
  • Is it a wrong approach to add a NSViewController in NSWindow - (void)setController:(NSViewController *)controller { [[currentController view] removeFromSuperview]; NSView *view = [controller view]; view.frame = ((NSView*)self.window.contentView).bounds; [_window setContentView:view]; //[_window.contentView addSubview:view]; } – york Nov 21 '12 at 05:57
  • No it is not. U can use NSWindowController or NSViewController ,either way u can achieve navigating between views – vignesh kumar Nov 21 '12 at 06:07
  • Can you please share some references as i am not getting how i navigate between views in cocoa, i created NSViewControllers but for navigation from one view to another i am using the above mentioned code. I want something like in iOS development (Navigation Controller type feature for COCOA) – york Nov 21 '12 at 06:12