Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reload NSCollectionView

I have NSCollectionView with full of items, have one scenario where after deletion of one item the collection view should be refresh and it should display update items.

I am able to delete item, but collection view is not refreshing,

googled a lot, but got nothing,

like image 580
PR Singh Avatar asked Mar 12 '14 07:03

PR Singh


2 Answers

NSCollectionView is a subclass of NSView. And you must be knowing MVC design pattern. View is intended only to show the data/values from the model.

In your case you must have some array. You need to update the array and set the content of NSCollectionView programmatically or using Cocoa Bindings.

- (void)setContent:(NSArray *)content;

Also you may need to refresh the view :

[yourCollectionView setNeedsDisplay:YES]
like image 126
Anoop Vaidya Avatar answered Sep 27 '22 21:09

Anoop Vaidya


Anoop's suggestion didn't work for, but following did, copied from here

Turns out that the NSCollectionView item views can be refreshed by setting the ItemPrototype, e.g.,

ItemPrototype = new SomeViewController()

This causes all the existing views to be recreated.

like image 33
dev Avatar answered Sep 27 '22 21:09

dev