誰か助けてください。異なるオブジェクトを含む配列に別のオブジェクトを追加することはできません
私はここで誰も私のpolyclinicsオブジェクトをすべて含む配列を作成しています。今度は、この配列にユーザーオブジェクト(patientDetailオブジェクト)を追加する必要があります。しかし、どのように私はviewDidLoadメソッドを変更するにもかかわらず、何かちょうど正しくないようだ..私はすべてのポイントを設定することはできません..私はすべてのコードを削除するときに、ユーザーオブジェクトを扱うそれは動作します.. Some1は以下の方法をお勧めしますか?私はあなたの配列の異なるクラスを持っているので、あなたがfor (PolyClinics *polyclinics1 in _listOfPolyClinics)
を使用することはできません読み取り=(
- (void)viewDidLoad {
[super viewDidLoad];
_annotation2 = [[NSMutableArray alloc] init];
CLLocation *userLoc = _mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
_annotations=[[NSMutableArray alloc] init];
_listOfPolyClinics = [[NSMutableArray alloc] init];
PatientDetails *patientDetails = [[PatientDatabase database]
patientDetails:_nric];
for (PolyClinics *polyclinics in [[PatientDatabase database]
polyClinics]){
[_listOfPolyClinics addObject:polyclinics];
}
[_listOfPolyClinics addObject:patientDetails];
for (PolyClinics *polyclinics1 in _listOfPolyClinics){
MyAnnotation* myAnnotation=[[MyAnnotation alloc] init];
if ([polyclinics1 isKindOfClass:[PatientDetails class]]){
CLLocationCoordinate2D theCoordinate3;
theCoordinate3.longitude = patientDetails.longitude;
theCoordinate3.latitude = patientDetails.latitude;
myAnnotation.coordinate = theCoordinate3;
myAnnotation.title = _nric;
myAnnotation.subtitle = [NSString stringWithFormat:@"%i",patientDetails.category];
}
else{
CLLocationCoordinate2D theCoordinate;
theCoordinate.longitude = polyclinics1.longtitude;
NSLog(@"Halo");
theCoordinate.latitude = polyclinics1.latitude;
NSLog(@"bye");
//myAnnotation.pinColor = MKPinAnnotationColorPurple;
myAnnotation.coordinate = theCoordinate;
myAnnotation.title = polyclinics1.name;
myAnnotation.subtitle = [NSString stringWithFormat:@"%i",polyclinics1.telephone];
}
[_mapView addAnnotation:myAnnotation];
[_annotation2 addObject:myAnnotation];
}
コンソールエラーとは何ですか?PatientDetailsの実装方法を表示できますか? – Cyprian
@Cyprianコンソールエラーはありません..それはちょうどそこに住んでいません...またはむしろ私は地図にこのユーザーを挿入..全体の地図は、私ができることができる前の拡大地図ではなく、世界地図を表示します。すべての私のポリクローニクス..あなたは何が問題なのか知っていますか? –