Re: NSPopUpButton failure after adding file names
Re: NSPopUpButton failure after adding file names
- Subject: Re: NSPopUpButton failure after adding file names
- From: Jyrki Wahlstedt <email@hidden>
- Date: Thu, 15 May 2003 15:58:33 +0300
Hi,
someone with more experience may confirm, but I'd guess the crash is
caused by one of the autoreleases in your function, could be pathname,
as it is picked from the directory.
It would, anyway, be consistent with the symptoms, that the crash comes
after returning from the function. I managed once to do something
similar, as in certain situations I autoreleased an object twice. Just
removed one to be happy again! You could try to comment those
autoreleases out to verify this theory.
This is what I did to populate my popup (not with filenames, but names
from an array in a tableview):
- (void)populateMatchPopUp:(NSArray *)players
{
int i, nMatches, nPlayers;
NSString *m1, *m2, *mc;
[matchPopUp removeAllItems];
nPlayers = [players count];
nMatches = nPlayers/2;
i = 0;
while (i < nPlayers) {
m1 = [[players objectAtIndex:i] objectForKey:PlayerKey];
m2 = [[players objectAtIndex:i+1] objectForKey:PlayerKey];
if ([m1 caseInsensitiveCompare:@"bye"] != NSOrderedSame &&
[m2 caseInsensitiveCompare:@"bye"] != NSOrderedSame) {
mc = [NSString stringWithFormat:@"%@-%@",m1,m2];
[matchPopUp addItemWithTitle:mc];
[matchCache setObject:[NSNumber numberWithInt:i] forKey:mc];
}
i += 2;
}
}
On torstai, touko 15, 2003, at 13:25 Europe/Helsinki, Rick Anderson
wrote:
I have an NSPopUpButton that I want to populate with the names of
files in a specific directory on launch. I'm calling a function from
awakeFromNib that handles this. The function that I wrote to do this
appears to work (at least, it gets through the code without any
apparent problem, but when it returns to awakeFromNib, the app dies
"due to signal 11 (SIGSEGV)."
I'm not sure what I'm doing that is causing this. I temporarily
rewrote the function and simply added the names of the files directly
and it worked perfectly (I did this wondering if perhaps some
character in the file names was causing problems since some of the
names contained punctuation.) However, when it try to add them by
actually enumerating through the files and adding the file names, then
this failure occurs. And to reiterate: it doesn't happen within the
function, but rather after the function returns.
Here's the function I wrote for adding the file names to the
NSPopUpButton. Is there some subtle problem with what I'm doing here?
- (void)populateTemplateMenu
{
NSDirectoryEnumerator *theDirectory = [[NSFileManager
defaultManager] enumeratorAtPath:@"templates/layouts/"];
NSMutableString *pathname = [[NSMutableString alloc] init];
NSMutableString *fullPath = [[NSMutableString alloc] init];
while (pathname = [theDirectory nextObject])
{
// establish the full path to the file
[fullPath setString:
@"/Users/rick/Development/pf/build/templates/layouts/"];
[fullPath appendString: pathname];
// isFilePackageAtPath requires full path
if ( ([[NSWorkspace
sharedWorkspace]isFilePackageAtPath:fullPath]) ||
([pathname isEqualToString:@".DS_Store"]) )
{
// skip any folders or bundles
[theDirectory skipDescendents];
}
else
{
// use the file name to build the layout menu
[storySectionMenu addItemWithTitle: pathname];
}
}
[theDirectory autorelease];
[pathname autorelease];
[fullPath autorelease];
}
--Rick Anderson
"The only difference between me and a madman
is that I am not mad." -- Salvador Dali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
!
! Jyrki Wahlstedt
! Sammonkatu 10 B 13 mob. +358-40-502 0164
! FI-87100 Kajaani
!
! Our life is no dream; but it ought to become one and perhaps will.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.