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

廉价感情. 提交于 2019-12-11 11:42:11

问题


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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/29161348/when-nstableview-load-second-time-its-customcell-subviews-change-its-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!