NSSearch Field Predicate Filter - objective-c

-(void) searchFieldChanged{
MPVTModelList *list = [[MPVTModelList alloc] initWithClass:[MassPOAssignmentModel class]];
[intersectionTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
// [searchIntersectionField setStringValue:[[[searchIntersectionField stringValue] stringByReplacingOccurrencesOfString:#"\\" withString:kMPVTBlankString] stringByReplacingOccurrencesOfString:#"\'" withString:kMPVTBlankString]];
[searchIntersectionField setStringValue:[searchIntersectionField stringValue]];
NSArray *array=[[NSArray alloc]init];
if([[[searchIntersectionField cell]placeholderString] isEqualToString:#"Pricing Org"]){
NSArray *tempArray=[[[searchIntersectionField stringValue] uppercaseString] componentsSeparatedByString:#","];
NSLog(#"tempArray %#",tempArray);
NSString * str=[[searchIntersectionField stringValue] uppercaseString];
NSLog(#"str is %#",str);
for(id item in tempArray ){
[intersectionTableView reloadData];
array=[[[self intersectionList]entities]filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"mpoPricingOrg.stringValue contains[cd] %#",item]];
NSLog(#" item is %#",item);
NSLog(#"insie if arr %#",array);
[list appendEntities:array];
NSLog(#"hello %#",[[searchIntersectionField cell]placeholderString]);
}
}
else{
NSLog(#"inside else");
array = [[self searchFieldController] updatePredicateWithFilterText:[searchIntersectionField stringValue] searchArray:[[self intersectionList] entities] searchTableView:intersectionTableView];
NSLog(#"in side else array %#",array);
[list appendEntities:array];
}
[self setIntersectionList:list];
[list release];
[intersectionTableView reloadData];
[intersectionTableView deselectAll:nil];
[super updatePlacard:intersectionTableView];
}
I have called this method in -(void)controltextDidEditing. But when I enter "China" the filter predicate works fine. But when I enter "China,Brazil" it only shows the record for China and not for Brazil. Please suggest a better way of doing it.

Related

NSRangeException while deleting UICollectionView cells

I'm trying to remove cells from UICollectionView in for.. in loop and every time I get NSRangeException. I can't understand why does it happen because firstly I sort my array and then trying to remove. So the problem is that I firstly try to send request to the server and only if response is succes my UICollectionView cells and array elements are removes. Here is my code:
Pass elements through the loop:
- (IBAction)deletePictures:(id)sender {
int i = 0;
if (selectedPhotosURL.count>0){
loadCount = (int)selectedPhotosURL.count;
//sorting an array (it works fine)
NSArray *indexPaths = sortMediaCollection.indexPathsForSelectedItems;
NSMutableArray *pathes = [NSMutableArray arrayWithArray:indexPaths];
NSSortDescriptor *highestToLowest = [NSSortDescriptor sortDescriptorWithKey:#"self" ascending:NO];
[pathes sortUsingDescriptors:[NSArray arrayWithObject:highestToLowest]];
[selecedCellsArray sortUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
return [str2 compare:str1 options:(NSNumericSearch)];
}];
NSLog(#"selectedCElls %#",selecedCellsArray);
for(NSIndexPath *indexPath in pathes) {
NSLog(#"indexPath in pathes is %ld",(long)indexPath.row);
AVMSMCell *cell = (AVMSMCell *)[sortMediaCollection cellForItemAtIndexPath:indexPath];
AVMDataStore *oneItem = [smArray objectAtIndex:indexPath.row];
NSString *contentId = oneItem.fileId;
if (i<selectedPhotosURL.count){
NSLog(#"indexPath second loop is %ld",(long)indexPath.row);
[self deleteUserPhotos:contentId : indexPath.row : cell]; // send request to the server it's ok too.
i++;
}
}
} else {
[self selectAtLeastOneFirst];
}
}
For example here I select 6 cells and my array sort with right order from up to down (5,4,3,2,1,0). Then I pass this elements in method with this order.
Request send method:
-(void)deleteUserPhotos : (NSString *)contentId : (NSInteger )pathRow : (AVMSMCell *) cell{
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)pathRow];
if (([selecedCellsArray containsObject:[NSString stringWithFormat:#"%#",rowNsNum]]) )
{
cell.selectedBG.backgroundColor = DANGER;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *token = [defaults objectForKey:#"token"];
NSString *header = [NSString stringWithFormat:#"Bearer %#",token];
NSDictionary *params = #{#"lang": #"en",#"content_id":contentId,#"project_id":[defaults objectForKey:#"project_id"]};
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:header forHTTPHeaderField:#"Authorization"];
[manager POST:#"http://example.com/api/project/delete-content" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(#"JSON: %#", responseObject);
if ([[responseObject objectForKey:#"result"] isEqualToString:#"success"]){
#try{
NSLog(#"pathRow in TRY %ld",(long)pathRow); // HERE I get wrong number after two or three elements already passed
[smArray removeObjectAtIndex:(unsigned int)pathRow];
[selecedCellsArray removeObject:[NSString stringWithFormat:#"%ld",(long)pathRow]];
cell.selectedBG.hidden = YES;
[sortMediaCollection reloadSections:[NSIndexSet indexSetWithIndex:0]];
loadCount--;
}
} #catch (NSException *e){
NSLog(#"something is bad %#",e);
[SVProgressHUD dismiss];
if (smArray.count<pathRow-1){
[smArray removeObjectAtIndex:(unsigned int)pathRow-1];
}
} #finally {
cell.selectedBG.hidden = YES;
[sortMediaCollection reloadSections:[NSIndexSet indexSetWithIndex:0]];
}
} else {
NSLog(#"can't delete photo!");
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(#"Error: %#", error);
errorEndSpinner
}];
}
}
So in method above I get wrong element number after two or three elements already passed i.e frist element is 5,then 4, then 2, 3,1,0.
And at this moment my #catch handle exception and trying to remove element with [smArray removeObjectAtIndex:(unsigned int)pathRow-1]; and then I get NSRangeException and my app crashing. What I do wrong?
I solved my problem with this answer and little bit modified my code.
I've got an NSRangeException because I removed my UICollectionView items through the loop. Instead I should better use multiple deleting instantly like this:
// Delete the items from the data source.
[self deleteItemsFromDataSourceAtIndexPaths:selectedItemsIndexPaths];
// Now delete the items from the collection view.
[sortMediaCollection deleteItemsAtIndexPaths:selectedItemsIndexPaths];
So now my code looks like:
Pass through the loop:
- (IBAction)deletePictures:(id)sender {
int i = 0;
if (selectedPhotosURL.count>0){
[SVProgressHUD showWithStatus:#"Deleting" maskType:SVProgressHUDMaskTypeBlack];
loadCount = (int)selectedPhotosURL.count;
NSArray *indexPaths = sortMediaCollection.indexPathsForSelectedItems;
NSMutableArray *pathes = [NSMutableArray arrayWithArray:indexPaths];
NSSortDescriptor *highestToLowest = [NSSortDescriptor sortDescriptorWithKey:#"self" ascending:NO];
[pathes sortUsingDescriptors:[NSArray arrayWithObject:highestToLowest]];
[selecedCellsArray sortUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
return [str2 compare:str1 options:(NSNumericSearch)];
}];
for(NSIndexPath *indexPath in pathes) {
AVMSMCell *cell = (AVMSMCell *)[sortMediaCollection cellForItemAtIndexPath:indexPath];
AVMDataStore *oneItem = [smArray objectAtIndex:indexPath.row];
NSString *contentId = oneItem.fileId;
if (i<selectedPhotosURL.count){
[self deleteUserPhotos:contentId : indexPath.row : cell pathes:pathes]; //pass array with pathes into 'deleteUserPhotos'
i++;
}
}
} else {
[self selectAtLeastOneFirst];
}
}
Main method:
-(void)deleteItemsFromDataSourceAtIndexPaths:(NSArray *)itemPaths {
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
for (NSIndexPath *itemPath in itemPaths) {
[indexSet addIndex:itemPath.row];
}
[smArray removeObjectsAtIndexes:indexSet];
}
-(void)deleteUserPhotos : (NSString *)contentId : (NSInteger )pathRow : (AVMSMCell *) cell pathes:(NSMutableArray*)selectedItemsIndexPaths{
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)pathRow];
if (([selecedCellsArray containsObject:[NSString stringWithFormat:#"%#",rowNsNum]]))
{
cell.selectedBG.backgroundColor = DANGER;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *token = [defaults objectForKey:#"token"];
NSString *header = [NSString stringWithFormat:#"Bearer %#",token];
NSDictionary *params = #{#"lang": #"en",#"content_id":contentId,#"project_id":[defaults objectForKey:#"project_id"]};
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:header forHTTPHeaderField:#"Authorization"];
[manager POST:#"http://example.com/api/project/delete-content" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(#"JSON: %#", responseObject);
if ([[responseObject objectForKey:#"result"] isEqualToString:#"success"]){
#try{
[selecedCellsArray removeObject:[NSString stringWithFormat:#"%ld",(long)pathRow]];
loadCount--;
if (loadCount==0){ //only there remove items from collectionview
// Delete the items from the data source.
[self deleteItemsFromDataSourceAtIndexPaths:selectedItemsIndexPaths];
// Now delete the items from the collection view.
[sortMediaCollection deleteItemsAtIndexPaths:selectedItemsIndexPaths];
[selectedPhotosURL removeAllObjects];
}
} #catch (NSException *e){
NSLog(#"something is bad %#",e);
[SVProgressHUD dismiss];
if (smArray.count<pathRow-1){
[smArray removeObjectAtIndex:(unsigned int)pathRow-1];
}
} #finally {
cell.selectedBG.hidden = YES;
[sortMediaCollection reloadSections:[NSIndexSet indexSetWithIndex:0]];
}
} else {
NSLog(#"can't delete photo!");
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(#"Error: %#", error);
errorEndSpinner
}];
}
}
Hope this will be helpful for somebody.
I was getting the same error but found that it had to do with a different class having a mirrored copy of the array, and that class accessing a deleted index.
You can add an Exception Breakpoint to see exactly where the exception is coming from. Useful for differentiating errors in your code with errors coming from the iOS SDK: NSRangeException when deleting last UICollectionViewCell

NRGridView won't show data from my core data database

I am building a app for a local football club. I want to show all players names and pictures in a grid. Therefore I am using the NRGridview. But it won't load up with my data. I have an NSArray with all players information. Here you see the method which generates this array.
- (NSArray *)getTeam
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:#"Team"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"sortOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
NSError *error = nil;
NSArray *mutableFetchResults = [self.genkDatabase.managedObjectContext executeFetchRequest:request error:&error];
NSLog(#"first error log %#", [error localizedDescription]);
if (mutableFetchResults == nil) {
NSLog(#"second error log %#", [error localizedDescription]);
}else if ([mutableFetchResults count] == 0){
NSLog(#"geen resultaten voor team");
}else{
NSLog(#"team names: %#",[mutableFetchResults valueForKey:#"name"]);
return mutableFetchResults;
}
return mutableFetchResults;
}
And this is what I do in the tableview.
- (NRGridViewCell*)gridView:(NRGridView *)gridView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyCellIdentifier = #"MyCellIdentifier";
NRGridViewCell* cell = [gridView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if(cell == nil){
cell = [[NRGridViewCell alloc] initWithReuseIdentifier:MyCellIdentifier];
[[cell textLabel] setFont:[UIFont boldSystemFontOfSize:11.]];
[[cell detailedTextLabel] setFont:[UIFont systemFontOfSize:11.]];
}
NSLog(#"players array %#",players);
for (int i = 0; i <= [players count]; i++) {
// NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[[players objectAtIndex:i]valueForKey:#"image"]]];
// UIImage *image = [[UIImage alloc]initWithData:imgData];
//cell.imageView.image = image;
cell.textLabel.text = [[players objectAtIndex:i]valueForKey:#"name"];
cell.detailedTextLabel.text = [[players objectAtIndex:i]valueForKey:#"position"];
return cell;
}
return cell;
}
The NSLog gives always (null). My question is now, where should I put the code "NSArray *players = [self getTeam] . so that my tableview will fill up with data?
EDIT
It did give me back the right amount of sections, and numberOfRowsInsection. For numbersOfRowsIn section I created 4 methods. 1 method whichs gets all off the goalkeepers, 1 for the defenders, 1 for the wingers, and 1 for the attackers. Then In my tableview method I did the following.
- (NSInteger)gridView:(NRGridView *)gridView numberOfItemsInSection:(NSInteger)section
{
if(section == 0){
return [[self getDoelmannen]count];
}else if (section == 1){
return [[self getVerdedigers]count];
}else if (section == 2){
return [[self getMiddenvelders]count];
}else{
return [[self getAanvallers]count];
}
return [[self getAanvallers]count];
}
This works. But still have the problem for my cell self.
EDIT2
Okay I think my problem is with filling my players Array up. I do the following in my viewDidLoad
-(void)viewDidLoad{
_players = [self getTeam];
NSLog(#"players array: %#",_players);
}
Which gives the following log.
2012-10-17 12:11:22.099 RacingGenk[63122:c07] nil
2012-10-17 12:11:22.099 RacingGenk[63122:c07] players array: (null)
Here is my code for getTeam
- (NSArray *)getTeam
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:#"Team"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"sortOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
NSError *error = nil;
NSArray *mutableFetchResults = [self.genkDatabase.managedObjectContext executeFetchRequest:request error:&error];
if (mutableFetchResults == nil) {
NSLog(#"nil");
}else if ([mutableFetchResults count] == 0){
NSLog(#"geen resultaten voor team");
}else{
NSLog(#"team names: %#",[mutableFetchResults valueForKey:#"name"]);
return mutableFetchResults;
}
return mutableFetchResults;
}
It looks like players isn't getting initialized. You can put your [self getTeam] call in the viewDidLoad method and make players a property.
If NRGridView is anything like UITableView, there are probably other methods that you need to overload.
For example, UITableView has tableView:numberOrRowsInSection:. Failure to return > 0 value from this method results in nothing being shown. Or numberOfSectionsInTableView:, which returns the number of sections and so on.
Check the documentation for the control you're using.
Update:
Since your executeFetchRequest:error: is failing, you should check if there's an error message instead of just printing out (nil):
NSLog(#"%#", [error localizedDescription]);

How to parse the string using TBXML in iphone sdk?

I tried to parse following String using TBXML.
<panel><start><post_id>4</post_id><user_id>2</user_id><post>Hyder here</post><created_on>2012-01-09 06:36:59</created_on><likes>0</likes><noc>0</noc><status>A</status></start><start><post_id>3</post_id><user_id>2</user_id><post>Hello hyder here</post><created_on>2012-01-09 06:34:09</created_on><likes>0</likes><noc>0</noc><status>A</status></start><start><post_id>2</post_id><user_id>0</user_id><post>Hi, This is Syed Hyder....</post><created_on>2012-01-09 01:07:36</created_on><likes>0</likes><noc>0</noc><status>A</status></start><start><post_id>1</post_id><user_id>0</user_id><post>Hello, gaurav....How are you.</post><created_on>2012-01-09 01:05:11</created_on><likes>0</likes><noc>0</noc><status>A</status></start></panel>
My code: -
NSMutableArray *newArr = [[NSMutableArray alloc] init];//21
RXMLElement *rxml = [[RXMLElement alloc] initFromXMLString:response];
[rxml iterate:#"panel.start" with:^(RXMLElement *start) {
ModelPost *newPost = [[ModelPost alloc] init];
newPost.message = [NSString stringWithFormat:#"%#", [start child:#"post"]];
NSLog(#"Post = %#", [start child:#"post"]);
[newArr addObject:newPost];
}];
but I am unable to do it or enter in the iterate loop.
Please help me to over come this by sample code, suggestions and tutorials.
Thanks in Advance....
- (void)xmlparserurl{
//xml data url calling....
tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:#"http://karen.webmascot.com/iapi/orders.php?max_count=10"]] retain];
records = [NSMutableArray array];
[records retain];
//retrieving all data from the xml
if (tbxml.rootXMLElement){
NSLog(#"inserting");
[self traverseElement:tbxml.rootXMLElement];
}
[tbxml release];
}
- (void)traverseElement:(TBXMLElement *)element {
do {
//NSLog(#"%#",[TBXML elementName:element]);
if (element->firstChild)
[self traverseElement:element->firstChild];
if ([[TBXML elementName:element] isEqualToString:#"start"]) {
//NSLog(#"xml element checking");
TBXMLElement *id = [TBXML childElementNamed:#"attribute name" parentElement:element];
//inserting into the mutable array
[records addObject:[NSArray arrayWithObjects:
[TBXML textForElement:elementname],
[TBXML textForElement:elementname],
[TBXML textForElement:elementname],nil]];
}
} while ((element = element->nextSibling));
[self.tableview reloadData];
}
i am only sending the code of retrieving the xml data. i am also sending the tutorial where you will get the answer of your further question.
http://www.tbxml.co.uk/TBXML/API.html

cancel button on search bar does not cancel correctly

I have a search bar, i can search now, but when I enter a text to search, and click the cancel button. It does not give me back my first stage, meaning full of the items in the table.
For example: I search the item with word: a, it gives me all the a items, yes, it is right now, but when i hit the cancel button, i want the programme gives me all the items exist, not just a items.
Here is the code: please help me out. Thank you so much.
- (void)searchBarCancelButtonClicked:(UISearchBar *)aSearchBar
{
searchBar.text = #"";
[searchBar resignFirstResponder];
letUserSelectRow = YES;
searching = NO;
self.tableView.scrollEnabled = YES;
NSLog(#"what text after cancel now: %#", searchBar.text);
[self.tableView reloadData];
}
- (NSMutableArray *) searchTableView {
NSString *searchText = searchBar.text;
NSLog(#"search text: %#", searchText);
NSMutableArray *resultArray = [[NSMutableArray alloc] init];
NSMutableArray *tempArr = [[NSMutableArray alloc] init];
for (NSDictionary *dTemp in arrayData)
{
NSString *tempStr = [dTemp objectForKey:#"url"];
NSLog(#"sTemp string: %#",[ NSString stringWithFormat:#"%#", tempStr]);
NSRange titleResultsRange = [tempStr rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
{
NSLog(#"1 count :%d", [resultArray count]);
[resultArray addObject:dTemp];
NSLog(#"2 count :%d", [resultArray count]);
[tempArr addObject:resultArray];
[resultArray release];
resultArray = [NSMutableArray new];
}
}
if (resultArray != nil) {
[resultArray release];
}
return tempArr;
}
- (void)searchBar:(UISearchBar *)aSearchBar textDidChange:(NSString *)searchText
{
NSLog(#"what text after cancel now: %#", searchBar.text);
if([searchText length] > 0) {
[sortedArray removeAllObjects];
searching = YES;
letUserSelectRow = YES;
self.tableView.scrollEnabled = YES;
NSMutableArray *searchArray = [self searchTableView];
sortedArray = [[NSMutableArray alloc] initWithArray:searchArray copyItems:YES];
for (int i = 0; i<[sortedArray count]; i++) {
NSLog(#"this is the search array: %#", [[sortedArray objectAtIndex:i] class]);
}
NSLog(#"sorted array: %d", [sortedArray count]);
}
else {
searching = NO;
letUserSelectRow = NO;
self.tableView.scrollEnabled = NO;
}
[self.tableView reloadData];
}
You don't need to override any of UISearchBar methods to accomplish this. The new way of doing this relies on the UISearchDisplay controller instead (specifically on shouldReloadTableForSearchString).
Declare your view controller to conform to UISearchDisplayDelegate protocol, and keep two instance variables: your model as NSArray (all data) and a filtered array as NSMutableArray (a subset of your data). The code you presently have in "searchTableView" would filter the content of the model and place it into the filtered NSMutableArray. Then you would override the following UITableView methods: -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section and -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath. In each, before returning, make a comparison to determine whether your tableView argument is equal to self.searchDisplayController.searchResultsTableView. If it is, the user is looking at the filtered list and your should use the content of the filtered NSMutableArray to create the view, otherwise, the user is looking at the whole data set and you should use the content of the NSArray that holds your model. Take a look at the following Apple code for a simple example of what I described:
http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

UITableView and SearchBar problem

I'm trying to add a Search bar to my UITableView. I followed this tutorial: http://clingingtoideas.blogspot.com/2010/02/uitableview-how-to-part-2-search.html.
I'm getting this error if I type a letter in the search box: Rooster(10787,0xa05ed4e0) malloc: *** error for object 0x3b5f160: double free
*** set a breakpoint in malloc_error_break to debug.
This error occurs here:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self handleSearchForTerm:searchString];
return YES;
}
(on the second line)
- (void)handleSearchForTerm:(NSString *)searchTerm {
[self setSavedSearchTerm:searchTerm];
if ([self searchResults] == nil) {
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults:array];
[array release];
}
//Empty the searchResults array
[[self searchResults] removeAllObjects];
//Check if the searchTerm doesn't equal zero...
if ([[self savedSearchTerm] length] != 0) {
//Search the whole tableList (datasource)
for (NSString *currentString in tableList) {
NSString *klasString = [[NSString alloc] init];
NSInteger i = [[leerlingNaarKlasList objectAtIndex:[tableList indexOfObject:currentString]] integerValue];
if(i != -1) {
klasString = [klassenList objectAtIndex:(i - 1)];
}
//Check if the string matched or the klas (group of school)
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound ||
[klasString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound) {
//Add to results
[[self searchResults] addObject:currentString];
//Save the klas (group of school). It has the same index as the result (lastname)
NSString *strI = [[NSString alloc] initWithFormat:#"%i", i];
[[self searchResultsLeerlingNaarKlas] addObject:strI];
[strI release];
}
[klasString release];
}
}
}
Can someone help me out?
Regards,
Dodo
The double free error means you have released an object more than needed. Here the suspicious object is klasString.
From your code:
NSString *klasString = [[NSString alloc] init];
...
if(i != -1) {
klasString = [klassenList objectAtIndex:(i - 1)];
}
...
[klasString release];
The assignment inside the if statement
loses reference to the newly allocated NSString, introducing a memory leak
makes the later release apply to the object from klassenList. When klassenList releases its elements, a double free error will occur.