objective c - Redraw NSView with subviews programatically -


this common question, efter trying find, still don't work.

i have nstableview want have nice looking view on when it's empty. looks this:

enter image description here

i have added tableview inside custom view (_superviewpackages) same size, , added code numberofrowsintableview function show/hide overlay:

if ( count == 0 && [[[_superviewpackages subviews] firstobject] isnotequalto:_viewoverlaypackages] ) {         [_superviewpackages addsubview:_viewoverlaypackages positioned:nswindowabove relativeto:nil];         [_viewoverlaypackages settranslatesautoresizingmaskintoconstraints:no];         nsarray *constraintsarray;         constraintsarray = [nslayoutconstraint constraintswithvisualformat:@"|-1-[_viewoverlaypackages]-1-|"                                                                    options:0                                                                    metrics:nil                                                                      views:nsdictionaryofvariablebindings(_viewoverlaypackages)];         [_superviewpackages addconstraints:constraintsarray];         constraintsarray = [nslayoutconstraint constraintswithvisualformat:@"v:|-1-[_viewoverlaypackages]-1-|"                                                                    options:0                                                                    metrics:nil                                                                      views:nsdictionaryofvariablebindings(_viewoverlaypackages)];         [_superviewpackages addconstraints:constraintsarray];     } else if ( count > 0 && [[_superviewpackages subviews] containsobject:_viewoverlaypackages] ) {         [_viewoverlaypackages removefromsuperview];     } 

this works, when remove last item in tableview, won't update until either click on tab , again, or on application , again , application redraws everything.

i have tried number of combinations of setneedsdisplay, setneedslayout , setneedsupdateconstraints on multiple different views none have worked. have moved updating own method , invoking performselectoronmainthread around threading problem.

i'm new objective-c, might obvious more experience, after reading , testing still can't find needs called update.

right have included code after adding last constraint:

[self performselectoronmainthread:@selector(updateview:) withobject:_viewoverlaypackages waituntildone:no]; 

in withobject arg have tried adding views can think of none have worked.

- (void)updateview:(nsview *)view {     nslog(@"updateview %@", view);     [view setneedsupdateconstraints:yes];     [view updateconstraintsforsubtreeifneeded];     [view setneedslayout:yes];     [view layoutsubtreeifneeded];     [view setneedsdisplay:yes];     [view display]; } 

edit: adding screenshots clarification.

when table view contains items, looks this:

enter image description here

but, when remove last item, , tableview becomes empty, want screenshot @ top of post. instead, looks until click on tab , back, or on application , etc. updates correctly.

enter image description here

so can tell, view gets added correctly, , have checked that, it's application doesn't redraw correctly until makes redraw (is guess).


Comments