I have a PlaceAnnotation class that I fill into an NSMutableArray. In viewDidLoad, i initiate ihatethis
_ihatethis = [[NSMutableArray alloc]init];
I use a MKLocalSearchCompletionHandler to search. And handle the mapitems like this:
for (MKMapItem *mapItem in [response mapItems]){
PlaceAnnotation *place = [[PlaceAnnotation alloc] init];
[place assignTitle:[[mapItem placemark] name];
[_ihatethis addObject:place];
}
[_ihatethis removeObjectAtIndex:2]; /*BAD ACCESS HERE*/
[_tableView reloadData];
This is my PlaceAnnotation.h file
@interface PlaceAnnotation : CLPlacemark <MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic) NSDictionary* dict;
//@property (nonatomic) NSURL *url;
@property (nonatomic) NSString *phoneNum;
@property (readonly) BOOL selected;
-(void)assignTitle:(NSString *)newTitle;
-(void)assignSelected:(BOOL) boolVal;
This is my PlaceAnnotation.m file
#import "PlaceAnnotation.h"
@interface PlaceAnnotation ()
@property (readwrite) NSString *title;
@property (readwrite) BOOL selected;
@end
@implementation PlaceAnnotation
-(void) assignTitle:(NSString *)newTitle {
if ( ![newTitle isEqualToString:[self title]]){
self.title = newTitle;
}
}
-(void) assignSelected:(BOOL)boolVal{
self.selected = boolVal;
}
@end
@end
This is my first post, I have read a ton of answers that responded to exc_bad_access questions and I cannot figure this out. So I think that somehow the placeannotations are getting forgotten and released. So when i go to delete is later it is gone. I really am confused and angry.