使用扩展了CLPlacemark的自定义类填充NSMutableArray后,访问异常 [英] Exc bad access after populating NSMutableArray with custom class extending CLPlacemark

查看:94
本文介绍了使用扩展了CLPlacemark的自定义类填充NSMutableArray后,访问异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PlaceAnnotation类,我将其填充到NSMutableArray中.在viewDidLoad中,我启动ihatethis

I have a PlaceAnnotation class that I fill into an NSMutableArray. In viewDidLoad, i initiate ihatethis

_ihatethis = [[NSMutableArray alloc]init];

我使用MKLocalSearchCompletionHandler进行搜索.并按以下方式处理mapitem:

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];

这是我的PlaceAnnotation.h文件

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;

这是我的PlaceAnnotation.m文件

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

这是我的第一篇文章,我已经阅读了许多回答exc_bad_access问题的答案,但我无法弄清楚.因此,我认为以某种方式忘记和发布了位置注释.因此,当我去删除后,它就消失了.我真的很困惑和愤怒.

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.

推荐答案

我更改了此

@interface PlaceAnnotation : CLPlacemark <MKAnnotation>

对此

@interface PlaceAnnotation : NSObject <MKAnnotation>

所以我想问题是出在CLPlacemark的解除分配上.谢谢

so i guess the problem was with the dealloc of CLPlacemark. Thanks

这篇关于使用扩展了CLPlacemark的自定义类填充NSMutableArray后,访问异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆