首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CLRegion上找不到属性标识符

在CLRegion上找不到属性标识符
EN

Stack Overflow用户
提问于 2013-09-08 13:16:27
回答 1查看 226关注 0票数 0

我有一个CLregions数组,这是我的代码:

代码语言:javascript
复制
NSArray *_regionArray;
NSArray *_geofences_regions;

... in the ViewDidLoad
_geofences_regions = [self buildGeofenceData];
....


- (NSArray*) buildGeofenceData {
    NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"regions" ofType:@"plist"];
    _regionArray = [NSArray arrayWithContentsOfFile:plistPath];

    NSMutableArray *geofences = [NSMutableArray array];
    for(NSDictionary *regionDict in _regionArray) {
        CLRegion *region = [self mapDictionaryToRegion:regionDict];
        [geofences addObject:region];
    }

    return [NSArray arrayWithArray:geofences];
}

- (CLRegion*)mapDictionaryToRegion:(NSDictionary*)dictionary {
    NSString *title = [dictionary valueForKey:@"title"];

    CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
    CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
    CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);

    CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];


    return [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
                                                   radius:regionRadius
                                               identifier:title];
}

在下面的代码中,the property identifier is not found on object of type id

为什么会这样呢?_geofences_regios[i]不应该返回一个CLRegion吗?

代码语言:javascript
复制
/*check for region*/
                        CLLocationCoordinate2D coordinate = [bestLocation coordinate];
                        for (int i=0; i<[_geofences_regions count]; i++) {
                            if ([_geofences_regions[i] containsCoordinate:coordinate]) {
                                [self.delegate locationManager:self regionEntered:_geofences_regions[i].identifier ];

}}区域/的/end检查

请回答以上问题,不要建议我使用其他委托方法,如didEnterRegion。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-08 13:26:49

这是因为数组返回的对象(默认情况下是没有id属性的identifier类型),可以执行强制转换以避免错误:

代码语言:javascript
复制
[self.delegate locationManager:self regionEntered:((CLRegion*)_geofences_regions[i]).identifier ];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18684096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档