【问题标题】:UIAlertView and UIAlertController IOS 9UIAlertView 和 UIAlertController IOS 9
【发布时间】:2015-12-28 13:19:32
【问题描述】:

我正在将项目 IOS8 编辑到 IOS 9,我很难找到在 IOS 9 中告诉我他已“弃用”的 UIAlertView 我现在用 UIAlertController 替换了 UIAlertView 但我发现了其他错误, 谁能帮我解决这个问题? 谢谢!

这是我的代码

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    Annotation *myAnnotation = (Annotation *)view.annotation;
    CLLocationCoordinate2D currentUserCoords = CLLocationCoordinate2DMake(myMapView.userLocation.coordinate.latitude, myMapView.userLocation.coordinate.longitude);
    CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(myAnnotation.coordinate.latitude, myAnnotation.coordinate.longitude);
    
    if ((CLLocationCoordinate2DIsValid(coord))&&(CLLocationCoordinate2DIsValid(currentUserCoords))) {
        Annotation *ann = (Annotation *)view.annotation;
        selectedCoords = ann.coordinate;
        
        NSString *strTitle = @"GPS";
        NSString *strMess = @"Close and open in maps?";
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle
                                                        message:strMess
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"OK", nil];
        [alert show];
        
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention"
                                                        message:@"It was not possible to determine the current location.\nPlease check in: /nSettings> Privacy> Location"
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    
    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;
        
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];
        
        if ([UIDevice currentDevice].systemVersion.intValue >= 7)
            pinView.tintColor = [UIColor colorWithRed:0.743 green:0.609 blue:0.432 alpha:1.000];
        
        
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
}

我试图用 UIAlertController 替换 UIAlertView。 这是结果

enter image description here

【问题讨论】:

    标签: uialertview uialertcontroller


    【解决方案1】:

    与 UIAlertView 不同,UIAlertController 声明略有不同且简单明了。 这是一个示例声明 -

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Any Title" message:@"Any Message" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *anyAction = [UIAlertAction actionWithTitle:@"ActionName" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //Any relevant method you want to call
        }];
    
        //Adding the alert action
        [alert addAction:anyAction];
    
        //Presenting the AlertController
        [self presentViewController:alert animated:YES completion:nil];
    

    有关高级实现细节,您可以参考我的一个示例实现here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 2015-12-17
      • 2015-05-20
      • 1970-01-01
      • 2016-01-02
      相关资源
      最近更新 更多