• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting selected items in a matrix
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting selected items in a matrix


  • Subject: Re: Getting selected items in a matrix
  • From: Nicholas Shanks <email@hidden>
  • Date: Sat, 23 Feb 2002 17:03:45 +0000

This reply is in two parts, (1) bugs in your code, and (2) a better way to write the method:


On Saturday, February 23, 2002, at 04:46 pm, Peter Schols wrote:

- (NSString *)setDay:(id)sender
{
int i;
NSArray *array = [[NSArray alloc] init];
array = [dayButton selectedCells];
while (i < [array count]) {
if ([[array objectAtIndex:i] state] == NSOnState) {
// code to add the Tag of the selected item to another array goes here }
}
}

1) You allocate an array with [[NSArray alloc] init], then throw away the reference to it by calling array = [dayButton selectedCells]. You could simply have put NSArray *array = [dayButton selectedCells]; which would avoid a memory leak.

2) Instead of your while loop, I would use an enumerator:

{
NSCell *currentCell;
NSEnumerator *enumerator = [[dayButton selectedCells] objectEnumerator];
while( currentCell = [enumerator nextObject] )
{
if( [currentCell state] == NSOnState )
{
// code to add the Tag of the selected item to another array goes here
}
}
}

Something to note: is "dayButton" an NSMatrix, or a cell within it? The name seems misleading to me.


Nicholas Shanks
--

http://nickshanks.com/
_______________________________________________
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.

  • Follow-Ups:
    • Re: Getting selected items in a matrix
      • From: John Hörnkvist <email@hidden>
References: 
 >Getting selected items in a matrix (From: Peter Schols <email@hidden>)

  • Prev by Date: Getting selected items in a matrix
  • Next by Date: Re: number formatting
  • Previous by thread: Getting selected items in a matrix
  • Next by thread: Re: Getting selected items in a matrix
  • Index(es):
    • Date
    • Thread