Загрузите представление карты в правильном пути - PullRequest
0 голосов
/ 14 декабря 2011

Я загружаю просмотр карты с аннотацией.Я написал код, как показано ниже.Поскольку я новичок в 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];
}

Возможно, я совершил много ошибок.Все предложения будут оценены.Спасибо

1 Ответ

0 голосов
/ 14 декабря 2011

Вот ссылка, которую вы можете предпочесть и знать, как правильно структурировать код http://www.highoncoding.com/Articles/804_Introduction_to_MapKit_Framework_for_iPhone_Development.aspx

Надеюсь, это поможет вам.

...