有人請幫忙。不能將另一個對象添加到包含不同對象的數組中
我是一個小菜鳥,剛剛創建了一個數組來包含我所有的polyclinics對象。現在我需要添加一個用戶對象(patientDetail對象)到這個數組中。但無論我如何修改viewDidLoad方法,似乎不太正確..我不能填充所有的點..只有當我刪除處理用戶對象的所有代碼,然後它的作品.. Some1請看看方法和建議?我需要因爲你有不同類別的patientDetail要添加的對象,並與綜合診所的其餘部分填充它...
感謝閱讀=(
- (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沒有控制檯錯誤..它只是沒有得到填充...或者當我插入這個用戶到地圖..整個地圖將顯示一個世界地圖。,而不是先前縮放的地圖,我可以c我所有的綜合診所......你知道什麼可能是問題嗎? –