Listing files in tableView

Discussion in 'Mac Programming' started by bker, May 25, 2010.

  1. bker macrumors newbie

    Joined:
    May 22, 2010
    #1
    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!


    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 filenamefileSystemRepresentation];
            
    path = [[openPanel filenamestringByStandardizingPath];
            [
    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< [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 fileListcount];
    }

    - (
    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 fileListobjectAtIndex:row];
        }
        return @
    "";
    }

    - (
    void)tableViewSelectionDidChange:(NSTableView *)tableView {
        
    NSLog(@"test");
    }

    @
    end

     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You need to call [table reloadData] to update the table view whenever its data changes.
     
  3. bker thread starter macrumors newbie

    Joined:
    May 22, 2010
  4. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Hamburg
    #4
    I am working on something very similar, but I need a way to find out when the files in the folder change. Is there some kind of NSNotification I can use to monitor the folder, to then call reloadData?
     
  5. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    Check out the FSEvents API.
     
  6. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Hamburg
    #6
    Thanks again kainjow, ill check it out now.
     
  7. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Hamburg
    #7
    Are there any tutorials for FSEvents?

    I cant make any sense out of the docs...
     
  8. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Hamburg
    #9
    thanks for that kainjow, I managed to setup the fsevent, but i am not sure on how to call this function from with the callback:
    Code:
    - (void) reloadFlashTableView
    {	
    	[flashArrayController setContent:[self flashContentArray]];
    	[flashTableView reloadData];
    	[self displayFlashCount];
    }
    and the callback:
    Code:
    void flashCallback(ConstFSEventStreamRef streamRef,
    					   void *clientCallBackInfo,
    					   size_t numEvents,
    					   void *eventPaths,
    					   const FSEventStreamEventFlags eventFlags[],
    					   const FSEventStreamEventId eventIds[])
    {
    	[SCPreferencesModule performSelectorOnMainThread:@selector(reloadFlashTableView) withObject:nil waitUntilDone:YES]; .....this causes the error...
    }
    error:
    Code:
    28/05/10 11:10:48 AM	Safari[50061]	+[SCPreferencesModule reloadFlashTableView]: unrecognized selector sent to class 0x1162e9f20
     
  9. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Hamburg

Share This Page