unrecognized selector sent to instance

Discussion in 'Mac Programming' started by scriptnoob, Jul 25, 2008.

  1. scriptnoob macrumors newbie

    Joined:
    Feb 28, 2008
    #1
    Hi all,
    I want to display list of files selected with NSOpenPanel in NSTableView with this code:

    Code:
    #import <Cocoa/Cocoa.h>
    
    
    @interface AppController : NSObject {
        IBOutlet NSTextField *tagTitle;
        IBOutlet NSTableView *filesTableView;
        NSArray              *openedFiles;
    }
    - (IBAction)showOpenPanel:(id)sender;
    - (void)openPanelDidEnd:(NSOpenPanel*)sheet
                 returnCode:(int)returnCode
                contextInfo:(void*)contextInfo;
    @end
    
    Code:
    #import "AppController.h"
    
    
    @implementation AppController
    
    - (IBAction)showOpenPanel:(id)sender
    {
        NSOpenPanel *panel = [NSOpenPanel openPanel];
    
        [panel setCanChooseFiles: YES];
        [panel setCanChooseDirectories: NO];
        [panel setAllowsMultipleSelection: YES];
        NSArray *fTypes = [NSArray arrayWithObjects: @"txt", nil];
    
        [panel beginSheetForDirectory: nil
                                 file: nil
                                types: fTypes
                       modalForWindow: [filesTableView window]
                        modalDelegate: self
                       didEndSelector: @selector(openPanelDidEnd:
                                                returnCode:
                                                contextInfo:)
                          contextInfo: nil];
    }
    
    - (void)openPanelDidEnd:(NSOpenPanel*)sheet
                 returnCode:(int)returnCode
                contextInfo:(void*)contextInfo
    {
        if (returnCode == NSOKButton) {
            openedFiles = [sheet filenames];
            [filesTableView reloadData];
        }
        // NSRunAlertPanel(@"Test: ", @"Test", nil, nil, nil);
    }
    
    - (int)numberOfRowsInTableView:(NSTableView *)tv
    {
        return [openedFiles count];
    }
    
    - (id)tableView:(NSTableView *)tv
        objectValueForTableColumn:(NSTableColumn *)tableColumn
                              row:(int)row
    {
        NSString *filename = [openedFiles objectAtIndex: 0];
        return filename;
    }
    
    @end
    
    but when I select files in NSOpenPanel and click Open I get this error:
    [NSRectSet objectAtIndex:]: unrecognized selector sent to instance 0x1b9030

    When line with
    Code:
    NSRunAlertPanel(@"Test: ", @"Test", nil, nil, nil);
    is uncommented everything works fine.
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
  3. scriptnoob thread starter macrumors newbie

    Joined:
    Feb 28, 2008

Share This Page