Re: NSArray problems
Re: NSArray problems
- Subject: Re: NSArray problems
- From: Hamish Allan <email@hidden>
- Date: Sat, 1 Feb 2003 17:13:53 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Lance,
'selectedCells' returns a list containing any cells in the matrix that
are selected - NOT those which are checked. For matrices of buttons
only one item is ever selected - the most recently pressed item. This
is similar to, for instance, a table that only allows single selection.
To achieve what you want to do, I think you must iterate over
[switchOutlet cells] checking whether ([cell state] == NSOnState).
As for your second question I don't know why directoryContentsAtPath
never returns, have you tried pressing the 'pause' button in the
debugger?
A couple of other things:
- - - I think you should be looking at '/Applications' rather than
'Macintosh HD/Applications'
- - - You're allocating memory for your NSFileManager and NSArray but
then losing your pointers to those instances. Try something like this
instead:
- - - (IBAction)dirAction:(id)sender
{
myMemberVariableArray = [[[NSFileManager defaultManager]
directoryContentsAtPath: @"/Applications"] retain];
}
Hope this helps,
Hamish
On Saturday, Feb 1, 2003, at 15:27 Europe/London, LANCE GREENWOOD wrote:
This is a two part question both using NSArray:
I have 5 switches and the user can check as many of them as they want,
and then press a button to process the checked buttons. I found in
the documentation "selectedCells" which is going to return an NSArray
with the check switches. Therefore, my code look like this:
//switchOulet is an outlet connected to the switch matrix.
-(IBAction)switchButton:(id)sender
{
int x;
NSArray *myArray;
myArray = [[NSArray alloc] initWithObjects: [switchOutlet
selectedCells]];
x = [myArray count];
}
x = 1 all the time and myArray always has nothing in it, can anyone
help in solving this problem and point me in the correct direction.
The second part of the question also has to do with NSArray, I want to
be able to get a list of the current directory so I used
"directoryContentsAtPath" When I call this function it never returns.
My code looks like this:
- (IBAction)dirAction:(id)sender
{
int i;
NSFileManager *fileManager;
NSArray *myArray;
fileManage =[[NSFileManager alloc] init];
fileManager =[NSFileManager defaultManager];
myArray = [[NSArray alloc] init];
myArray = [fileManager directoryContentsAtPath:@"Macintosh
HD/Applications"];
i = [myArray count];
}
Any help that can be given would be greatly appreciated.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (Darwin)
iD8DBQE+PABV6gc2d//pELYRArSdAJsGFqzXGxzP7V+T9ioznhlmhZ8hhACeOAkP
KXL1Q+4XD+m3O/HoMqC74CI=
=KzH1
-----END PGP SIGNATURE-----
_______________________________________________
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.