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)setPC1id)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"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;
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)setPC1id)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"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;