PR Singh
PR Singh

Reputation: 653

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,

Upvotes: 7

Views: 3327

Answers (2)

dev
dev

Reputation: 2200

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.

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46533

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]

Upvotes: 7

Related Questions