У меня есть две информационные кнопки, отображаемые в моем представлении выноска по какой-то причине. У меня есть 3 разных цвета контактов, которые извлекают информацию из трех разных источников. Мне нужна каждая кнопка для каждого цвета штыря, чтобы нажать на отдельный контроллер представления на основе этого класса аннотации. У меня есть следующий код до сих пор для моих 3-х различных цветов штыря:2 AccessoryItems при выноске, показывающем
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[annotation class]]) {
MKPinAnnotationView *view = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (view == nil) {
view = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:identifier];
} else {
view.annotation = annotation;
}
if([[(Annotation*)annotation phoneNumber] isEqualToString:@"0"]){
view.enabled = YES;
view.canShowCallout = YES;
view.pinColor = MKPinAnnotationColorPurple;
// Create a UIButton object to add on the
self.leftBtn = [UIButton buttonWithType:UIButtonTypeInfoDark];
[self.leftBtn setTitle:annotation.title forState:UIControlStateNormal];
[view setLeftCalloutAccessoryView:self.leftBtn];
}else{
view.enabled = YES;
view.canShowCallout = YES;
// Create a UIButton object to add on the
self.rightBtn = [UIButton buttonWithType:UIButtonTypeInfoDark];
[self.rightBtn setTitle:annotation.title forState:UIControlStateNormal];
[view setRightCalloutAccessoryView:self.rightBtn];
}
if ([[(Annotation*)annotation phoneNumber] isEqualToString:@"1"]){
view.enabled = YES;
view.canShowCallout = YES;
view.pinColor = MKPinAnnotationColorGreen;
// Create a UIButton object to add on the
self.leftBtn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[self.leftBtn setTitle:annotation.title forState:UIControlStateNormal];
[view setLeftCalloutAccessoryView:self.leftBtn];
}
return view;
}
return nil;
}
И для моего аксессуара похлопал метод я следующее:
- (void)mapView:(MKMapView *)map annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
if(view.leftCalloutAccessoryView){
UserAnnotation *annotate = view.annotation;
BuydealsViewController *dealsView=[[BuydealsViewController alloc]initWithNibName:@"DealDetailsViewViewController" bundle:[NSBundle mainBundle]];
dealsView.urlString = annotate.url;
[self.navigationController pushViewController:dealsView animated:YES];
}
if(view.rightCalloutAccessoryView){
MapDealViewController *mapDeals = [[MapDealViewController alloc] init];
Annotation *annView = view.annotation;
mapDeals.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
mapDeals.phoneNumber = annView.phoneNumber;
mapDeals.address = annView.subtitle;
mapDeals.title = annView.title;
mapDeals.description = annView.description;
mapDeals.value = annView.value1;
mapDeals.discountPercent = annView.discountPercent;
mapDeals.price = annView.price;
mapDeals.header = annView.header;
mapDeals.imageUrl = annView.imageUrl;
mapDeals.url = annView.url;
mapDeals.dealy = annView.dealy;
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:mapDeals animated:YES];
}
}
Есть ли способ, чтобы сделать их как правильные кнопки, но нажмите, чтобы разделить виды?
Woah, это было потрясающе! Да, я не понимал, что установил условия для своего MKUserLocation для аннотации, а другой для моего класса Annotation. Спасибо тебе за это! –