我正在编辑IOS8到IOS 9的项目,我很难找到UIAlertView,在IOS 9中告诉我他已经"已弃用" 我现在用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;
}
&#13;
我尝试用UIAlertController替换UIAlertView。 这是结果
答案 0 :(得分: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