0

i am having a programatically created NSCollectionview

_upcomingVideosCollection = [[NSCollectionView alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 300, 1200))];
_upcomingVideosCollectionItem = [Videos new];

Videos.m

#import "Videos.h"
@property (strong, retain) IBOutlet NSButton *href_reject;
@end
int i=0;

@implementation Videos

- (void)viewDidLoad {
    [super viewDidLoad];
   }

-(void)setRepresentedObject:(id)representedObject{
    [super setRepresentedObject:representedObject];
    if (representedObject !=nil)
    {
    [_href_reject setTag:i];        
    i=i+1;
    }

}


- (IBAction)removeVideo:(id)sender {
  nslog(@"%d",[sender tag]) 
}

@end

When i am trying to load new data in the collectionview using

[_upcomingVideosCollection setItemPrototype:[Videos new]];
[_upcomingVideosCollection setContent:contents];

the new items [sender tag] are not refreshed and they increment

Ex: first data load, i have 3 objects in contents so the tag would be from 0-2 When i am loading another contents ex:10 objects, instead of 0-9 i have 0-11.

**UPDATE:

@vitormm Solved the problem using [collection setContent:@[]]; before the real setContent

  • When you load the new data, you are also setting x to 0? Otherwise it will keep its last value. – VitorMM Jul 14 '16 at 12:35
  • i am reseting x to 0, but the representedObject keeps memorizing all the data.. – Bonta Alexandru Jul 14 '16 at 13:57
  • Once a had a problem with representedObject memorizing data. It was solved by using `[collection setContent:@[]];` before the real setContent. That clears the representedObjects. – VitorMM Jul 14 '16 at 14:00
  • I've also used a `[collection setNeedsDisplay:YES];` after that line, before the real setContent, just in case, but I'm not sure if it's needed. – VitorMM Jul 14 '16 at 14:01
  • @vitormm you save my day! it's now working if i use setContent:@[] – Bonta Alexandru Jul 14 '16 at 14:03

0 Answers0