Ios 带有UIAlertView的接点注释

Ios 带有UIAlertView的接点注释,ios,uialertview,Ios,Uialertview,我在“底部栏”中创建了一个按钮。当用户按下按钮时,我试图显示UIAlertView,以便用户可以输入一个地址,从而在地图上显示一个蓝色pin。然后应将该pin保存为NSUserDefault,以便每次重新启动应用程序时都保存该位置 这是我到目前为止所拥有的。用户可以在UIAlertView中输入地址,但不会发生任何事情 - (IBAction)selectHq:(UIBarButtonItem *)sender { UIAlertView *alert = [[UIAlertView

我在“底部栏”中创建了一个按钮。当用户按下按钮时,我试图显示UIAlertView,以便用户可以输入一个地址,从而在地图上显示一个蓝色pin。然后应将该pin保存为NSUserDefault,以便每次重新启动应用程序时都保存该位置

这是我到目前为止所拥有的。用户可以在UIAlertView中输入地址,但不会发生任何事情

- (IBAction)selectHq:(UIBarButtonItem *)sender
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Select Headquarters"
                                                    message:@"Enter Address"
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Ok", nil];


    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

    [alert show];

    UITextField *field = [alert textFieldAtIndex:0];
    field.placeholder = @"Enter HQ Address";


    if (!self.geocoder)
    {
        self.geocoder = [[CLGeocoder alloc] init];
    }

    NSString *hqAddress = [NSString stringWithFormat:@"%@", field.text];

    [self.geocoder geocodeAddressString:hqAddress completionHandler:^(NSArray *placemarks, NSError *error) {
        if ([placemarks count] > 0)
        {
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            CLLocation *location = placemark.location;
            CLLocationCoordinate2D hqCoordinate = location.coordinate;

            NSLog (@"%f %f", hqCoordinate.latitude, hqCoordinate.longitude);




            MKCoordinateRegion region;
            MKCoordinateSpan span;
            span.latitudeDelta = 0.01;
            span.longitudeDelta = 0.01;
            region.span = span;
            region.center = hqCoordinate;

            MKPointAnnotation *hqAnnotation = [[MKPointAnnotation alloc] init];
            [hqAnnotation setCoordinate:hqCoordinate];
            [hqAnnotation setTitle:@"HQ"];
            [[self mapView] addAnnotation:hqAnnotation];

            [self.mapView setRegion:region animated:TRUE];
            [self.mapView regionThatFits:region];




        }
    }];


    [[NSUserDefaults standardUserDefaults] setObject:field.text forKey:HQ_KEY];
    [[NSUserDefaults standardUserDefaults] synchronize];

您应该实现
UIAlertViewDelegate
,并将警报按钮选择的操作代码放入delegate方法中

- (IBAction)selectHq:(UIBarButtonItem *)sender
{
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Select Headquarters"
                                                    message:@"Enter Address"
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Ok", nil];


    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

    [alert show];
    [alert release]  // if non-arc project.
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    // add your code here for tagging the map 
    // saving to nsuserdefaults.
  }

它正在工作。别针是紫色的。“我怎样才能把别针的颜色改成蓝色?”乔治·弗雷迪看着。这可能对你有帮助。