不知道我哪里错了。我有一个最多包含 3 个对象的数组。我想检查是否有任何数组对象超过 0,如果是,请将它们格式化为NSString
. 如果没有,我想在索引 0 处包含对象。
朝着正确的方向前进会很棒!
// add annotation
MKPointAnnotation *point = [MKPointAnnotation new];
point.coordinate = (CLLocationCoordinate2D){[self.eventPlan.location_lat doubleValue], [self.eventPlan.location_lng doubleValue]};
NSArray *locationA = [self.eventPlan.location_address componentsSeparatedByString:@", "];
point.title = locationA[0];
if ([locationA containsObject:locationA[1]]) {
point.subtitle = [NSString stringWithFormat:@"%@, %@", locationA[1], locationA[2]];
} else {
point.subtitle = [NSString stringWithFormat:@"%@", locationA[1]];
}
[mapView addAnnotation:point];