【发布时间】:2011-10-19 16:58:05
【问题描述】:
我有一个 TabBar 应用程序和 2 个视图。
一个视图是带有注释和标注等的 MKMapView。一切正常。单击标注中的“UIButtonTypeDetailDisclosure”按钮会触发我的“showDetails”函数(NSLOG ..)。
现在我想在'showDetails'中推送一个DetailView。我必须使用pushViewController 或presentModalViewController
#pragma mark - MKMap methods
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
if([annotation isKindOfClass:[CustomPlacemark class]])
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]];
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
newAnnotation.enabled = YES;
//newAnnotation.pinColor=MKPinAnnotationColorPurple;
NSLog(@"Created annotation at: %f %f", ((CustomPlacemark*)annotation).coordinate.latitude, ((CustomPlacemark*)annotation).coordinate.longitude);
[newAnnotation addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:@"GMAP_ANNOTATION_SELECTED"];
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftIconView.png"]];
newAnnotation.leftCalloutAccessoryView = leftIconView;
[leftIconView release];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
newAnnotation.rightCalloutAccessoryView = rightButton;
[newAnnotation autorelease];
return newAnnotation;
}
return nil;
}
- (void) showDetails:(id)sender {
NSLog(@"Annotation Click");
[self.navigationController pushViewController:self.detailViewController animated:YES];
// I want to push a new View here...
}
不幸的是,这并没有做任何事情(没有错误/没有行动)。我想这是因为我没有navigationController 可以使用pushViewController。
- (void) showDetails:(id)sender {
NSLog(@"Annotation Click");
[self.navigationController pushViewController:self.detailViewController animated:YES];
// I want to push a new View here...
}
单击通知中的“UIButtonTypeDetailDisclosure”按钮时,我正在尝试在 navigationController 中创建和推送 DetailViewController。但 navigationController 为零 知道要在我的“showDetails”函数中添加什么吗?
非常感谢
【问题讨论】:
标签: iphone cocoa-touch uinavigationcontroller pushviewcontroller