Newbie Class question

Discussion in 'Mac Programming' started by Pygar, Sep 28, 2005.

  1. Pygar macrumors newbie

    Sep 28, 2005
    Hi All,

    I'm a real newbie to Obj-C, and i'm trying to put together a new method call. I would like to have a button click trigger a method which asks the user to select some files. these files are returned to a textFiled.
    Most of this code is directly from Apple's 'using NSOpenPanel'.

    The application seems to run fine for a few method calls, but then locks around the 4th or 5th call leaving the button depressed. Can anyone spot any mistakes. Maybe i'm going about this the wrong way.
    Many thanks folks, Pygar.

    - (IBAction)setPC1:(id)sender
    NSString *total = [fileInfo setProg];
    [name1 setStringValue:total];

    @interface FileInfo : NSObject
    NSString *pCString;
    NSString *sNOnly;
    NSString *pCFile;
    - (NSString *) setProg;

    @implementation FileInfo
    - (NSString *) setProg;
    int result;
    NSArray *fileTypes = [NSArray arrayWithObject:mad:"txt"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];
    [oPanel setAllowsMultipleSelection:YES];
    result = [oPanel runModalForDirectory:NSHomeDirectory()
    file:nil types:fileTypes];
    if (result == NSOKButton) {
    NSArray *filesToOpen = [oPanel filenames];
    // int i, count = [filesToOpen count];
    // for (i=0; i<count; i++) {
    NSString *aFile = [filesToOpen objectAtIndex:i];
    pCFile = [[NSString alloc] initWithString:aFile];
    NSLog(@"%@", pCFile);
    sNOnly = [[NSString alloc] init];
    sNOnly = [pCFile lastPathComponent];
    NSLog (@"%@", sNOnly);
    return sNOnly;
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    First off you are leaking RAM. Every time you call alloc/init you need to call release or autorelease. If you don't the memory will hang around for ever.

Share This Page