Hi,
I have a tableView and an open dir button. i would like to list all files in a folder in the tableView when i push the open button. Here is what i did, it works well but only when i push the button it does not work. can you please help me. thanks!
I have a tableView and an open dir button. i would like to list all files in a folder in the tableView when i push the open button. Here is what i did, it works well but only when i push the button it does not work. can you please help me. thanks!
PHP:
//
// FileList.m
// FileList
#import "FileList.h"
@implementation FileList
- (IBAction)buttonOpen:(id)sender {
// Open panel
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setTreatsFilePackagesAsDirectories:NO];
[openPanel setCanChooseFiles:NO];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setCanChooseDirectories:YES];
[openPanel beginSheetForDirectory:[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"]
file:nil
types:nil
modalForWindow:window
modalDelegate:self
didEndSelector:@selector(didEndOpenSheet:returnCode:contextInfo:)
contextInfo:NULL];
}
- (void)didEndOpenSheet:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSOKButton) {
[[openPanel filename] fileSystemRepresentation];
path = [[openPanel filename] stringByStandardizingPath];
[self fileList]; // When i push the button i would like to list files in tableView
}
}
- (NSString *)directory {
NSString *directory = [NSString stringWithFormat:@"%@/", path];
return directory;
}
- (NSArray *)fileList {
NSMutableArray *array = [NSMutableArray array];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *fileList = [fileManager directoryContentsAtPath:[self directory]];
for (int j = 0; j < [fileList count]; j++) {
NSString *file = [NSString stringWithFormat:@"%@%@", [self directory], [fileList objectAtIndex:j]];
[array addObject:file];
}
return array;
}
// Begin tableView
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [[self fileList] count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
NSString *identifier = [tableColumn identifier];
if ([identifier isEqualToString:@"index"]) {
return [NSString stringWithFormat:@"%d", row + 1];
}
if ([identifier isEqualToString:@"value"]) {
return [[self fileList] objectAtIndex:row];
}
return @"";
}
- (void)tableViewSelectionDidChange:(NSTableView *)tableView {
NSLog(@"test");
}
@end