我有一個TabBar應用程序和2個視圖。 一個視圖是帶有註釋和標註等的MKMapView。所有效果都很好。點擊標註中的'UIButtonTypeDetailDisclosure'按鈕我的'showDetails'函數會觸發(NSLOG ..)。 現在我想在'showDetails'中推送一個DetailView。我必須要麼使用pushViewController
或presentModalViewController
pushViewController問題
#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...
}
我想創建並在navigationController推DetailViewController我的「UIButtonTypeDetailDisclosure」在通知按鈕被點擊時。但navigationController是零 任何想法添加到我的'showDetails'功能?
非常感謝
謝謝,我試過但它不適合我。我得到2警告消息:警告:沒有'-detailController'方法找到 和警告:'UINavigationController'可能不會響應'-detailController'... – Jan
爲什麼這樣:'UINavigationController * navigationController = [[UINavigationController alloc] detailController] ;'?你需要**'initWithRootViewController' **或者其他東西。 – WrightsCS
我編輯了代碼。它應該是'[navigationController setView:detailController.view];'。抱歉,是我的錯 –