In XIB file I have a collection view which contains a button. In awake from Nib i have defined several of buttons with different images. So the application basically looks like a finder, but does not perform any actions yet.
What I want to do now, is that when pressing each button a different file opens (I use filemanager method). I can do this easily in non-collection view type application, but when using collection view I am not sure how to attach different action to each button.
This is what I have, but that would open the same pdf.pdf for every button, when I want every button to open different pdf.
@implementation AppController
-(void) awakeFromNib {
MyButton *Button1 = [[MyButton alloc] init];
Button1.image = [NSImage imageNamed:@"img1"];
MyButton *Button2 = [[MyButton alloc] init];
Button2.image = [NSImage imageNamed:@"img2"];
MyButton *Button3 = [[MyButton alloc] init];
Button3.image = [NSImage imageNamed:@"img3"];
_modelArray = [[NSMutableArray alloc] init];
[controller addObject:Button1];
[controller addObject:Button2];
[controller addObject:Button3];}
- (IBAction)OpenCVFile:(id)sender {
NSFileManager *fileManagerCv = [[NSFileManager alloc] init];
NSString *filePath = @"Users/Tom/pdf.pdf";
if ([fileManagerCv fileExistsAtPath:filePath]) {
NSLog(@"File exists");
[[NSWorkspace sharedWorkspace]openFile:filePath withApplication:@"Finder"];}
else {
NSLog(@"File does not exist");
}
}
Could anyone help? Any help would be appreciated.