Possible Duplicate:
NSMutableArray addObject not affecting count?
I'm creating a search function that searches the NSArray catalogArray
for any instance of a particular string defined in searchMe.text
. Once a match is discovered, I'd like to add the objects to the mutable array searchResultMA
, but so far I get null results.
Here's my search method:
-(IBAction)searchFor{
int i=0;
for (int j=0; j<[catalogMA count]/170; j++) {
NSRange rangeArray = NSMakeRange(j*170, 170);
catalogArray = [catalogMA subarrayWithRange:rangeArray];
if([catalogArray containsObject:searchMe.text]) {
NSLog(@"catalogArray count=%d", [catalogArray count]);
[searchResultMA addObjectsFromArray:catalogArray];
NSLog(@"%d, %@", i, [searchResultMA objectAtIndex:9+i*170]);
i++;
}
}
}
and, here is my console output when I search for a string that I know has two instances in the array:
2013-01-08 18:07:05.300 Catalog[3229:c07] catalogArray count=170
2013-01-08 18:07:05.301 Catalog[3229:c07] 0, (null)
2013-01-08 18:07:05.301 Catalog[3229:c07] catalogArray count=170
2013-01-08 18:07:05.302 Catalog[3229:c07] 1, (null)
Why do I get a (null)
result from searchResultsMA
?
When I add in the line NSLog(@"%d, %d", i, [searchResultMA count]);
within the conditional, I get 0,0
and 1,0
, which tells me that there's nothing in the searchResultMA
mutable array. It was supposed to be 0,170
and 1,340
. Thoughts? Tips? Suggestions? All welcome...