2011-12-14 1 views
0

注釈付きのマップビューをロードしています。私は次のようにコードを書いています。私はOOPSを初めて熟知しているので、私は多くの間違いを犯している可能性があることを知っています。誰かが私のコードを見直していくつかの提案をするのなら、本当に役に立ちます。マップビューを正しい方法でロードする

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

if(groupOrContactSelected){ 
    UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.infoButton]; 
    UIBarButtonItem *segmentedButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; 
    flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
    NSArray *toolbarItems = [NSArray arrayWithObjects: infoButtonItem, flexibleSpace, segmentedButton, nil]; 
    [self setToolbarItems:toolbarItems]; 
    self.navigationController.toolbar.translucent = true; 
    self.navigationController.toolbarHidden = NO; 
    [infoButtonItem release]; 
    [segmentedButton release]; 
    [flexibleSpace release]; 

    mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    mapView.delegate=self; 

    [self.view addSubview:mapView]; 

    addressbook = ABAddressBookCreate(); 

    for (i = 0; i<[groupContentArray count]; i++) { 

     person = ABAddressBookGetPersonWithRecordID(addressbook,[[groupContentArray objectAtIndex:i] intValue]); 
     ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty); 
     NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty); 
     for (NSDictionary *addressDict in address) 
     { 
      addAnnotation = nil; 
      firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 
      lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 
      NSString *country = [addressDict objectForKey:@"Country"]; 
      NSString *streetName = [addressDict objectForKey:@"Street"]; 
      NSString *cityName = [addressDict objectForKey:@"City"]; 
      NSString *stateName = [addressDict objectForKey:@"State"]; 
      NSString *fullAddress = [streetName stringByAppendingFormat:@"%@/%@/%@", cityName, stateName, country]; 
      mapCenter = [self getLocationFromAddressString:fullAddress]; 
      if(stateName != NULL || country != NULL || streetName != NULL || cityName != NULL){ 

       addAnnotation = (SJAddressAnnotation *)[mapView dequeueReusableAnnotationViewWithIdentifier:[groupContentArray objectAtIndex:i]]; 

       if(addAnnotation == nil){ 
        addAnnotation = [[[SJAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:[groupContentArray objectAtIndex:i] ]         autorelease]; 
        [mapView addAnnotation:addAnnotation];} 
      } 
     } 
     CFRelease(addressProperty); 

    } 
    [self zoomToFitMapAnnotations:mapView]; 

    [self.navigationItem setHidesBackButton:YES animated:YES]; 
    NSString *mapTitle = localizedString(@"MAP_TITLE"); 
    [self setTitle:mapTitle]; 
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 

    NSString *close = localizedString(@"CLOSE"); 
    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:close style:UIBarButtonItemStylePlain target:self action:@selector(onClose:)]; 

    self.navigationItem.rightBarButtonItem = closeButton; 
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; 
    [closeButton release]; 
} 

[searchDirectionSegmentedControl release]; 
[mapView release]; 
} 

私は多くの間違いを犯している可能性があります。すべての提案は高く評価されます。おかげ

+0

どのようなやり方で、何に関係しているのでしょうか? – Sarah

+0

@ Sarah ...最も重要なのは、マップビューを読み込んでいて、コード内の適切な場所から注釈を追加しているかどうかを知りたがっています。他の間違いが指摘されていれば、本当に役立つでしょう。 –

答えて

関連する問題