objective-cmacoscocoanstableviewnstableviewcell

When NSTableview Load second time its customcell Subview's change it's position how to solve


I am new for cocoa OSX application might be this question is simple but i try my best to find out this issue and at the end i asking question here.

I am creating NSWindowViewController and in side it i Used NSTableview with Customcell. In customeCell i used NSView (customView) and all Cell IBOutlet put in side NSView. When First time that NSWindowViewController load that show fine but after close the window and again i open it. its NSTextField IBOutlet change its position top to bottom of the cell.

I try to find this some property change but did not fix it i attach its screen example what was happen with my cocoa osx Application.

enter image description here


Solution

  • I notice that this happen when i used following code for setting NSview's background color from property Inspector i setting NSView Core animation like.

    enter image description here

    And set background color in viewForTableColumn like:

    cellView.bgview.layer.backgroundColor = [NSColor whiteColor].CGColor;
    

    Color set properly and all working fine when i reload table view that top label going to bottom and that will display revers UI order for cell as i show in my question.

    And i tested with if i remove NSView setting background color code as i mention above then working perfect no re-order and all things. I am not using Auto-layout.

    So after then i create custom subclass of NSview for setting color like following:

    - (void)drawRect:(NSRect)dirtyRect {
    
    
        [[NSColor whiteColor] setFill];
        NSRectFill(dirtyRect);
    
        [super drawRect:dirtyRect];
    
        // Drawing code here.
    }
    

    I remove my old code and use this one for setting background by creating NSView subclass and my issue fix.