Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Pygar

macrumors newbie
Original poster
Sep 28, 2005
1
0
UK
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.

Controller.m
- (IBAction)setPC1:(id)sender
{
NSString *total = [fileInfo setProg];
[name1 setStringValue:total];
}

Model.h
@interface FileInfo : NSObject
{
NSString *pCString;
NSString *sNOnly;
NSString *pCFile;
}
- (NSString *) setProg;
@end

Model.m
@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;
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Pygar said:
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.