0

我在带有标注的 MKMapView 中有注释。在此标注中有一个“右箭头”按钮。单击它时,我想打开一个详细信息视图,一个带有自己的 nib 文件的额外 UIViewController 等。我使用以下代码:

在我的 MapViewController 中:

- (void)showDetails:(id)sender {
    // the detail view does not want a toolbar so hide it
    [self.navigationController setToolbarHidden:YES animated:NO];
    NSLog(@"pressed!");
    [self.navigationController pushViewController:self.detailViewController animated:YES];
    NSLog(@"pressed --- 2!");
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Annotation *) annotation {

    if(annotation == map.userLocation) return nil;

    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";


    MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                           initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
    customPinView.pinColor = MKPinAnnotationColorRed;
    customPinView.animatesDrop = YES;
    customPinView.canShowCallout = YES;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self
                                    action:@selector(showDetails:)
                forControlEvents:UIControlEventTouchUpInside];
    customPinView.rightCalloutAccessoryView = rightButton;

    UIImageView *memorialIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"googlemaps_pin.png"]];
    customPinView.leftCalloutAccessoryView = memorialIcon;
    [memorialIcon release];

    return customPinView;


}

该按钮有效,因为当我在 showDetais 方法中提供 NSLog 时,它会打印到控制台。问题是,什么都没有发生。单击按钮时,就像没有任何按钮一样。没有调试错误或异常,什么都没有。

MapView 标头看起来像这样:

@interface MapViewController : UIViewController <MKMapViewDelegate> {
    MKMapView *map;
    NSMutableDictionary *dictionary;
    EntryDetailController *detailViewController;
}

@property (nonatomic,retain) IBOutlet MKMapView *map;
@property (nonatomic,retain) IBOutlet EntryDetailController *detailViewController;

也许你们中的某个人可以帮助我:)

谢谢!

4

4 回答 4

1

检查你的viewController是否有导航控制器,如果它只是一个viewController那么它不能推送一个viewController,因为它没有导航控制器。

于 2010-09-03T06:43:16.247 回答
0

我过去也遇到过同样的问题,所以我只是使用不同的代码来切换视图:

-(IBAction)showDetails:(id)sender
{
    NSLog(@"button clicked");
    MapViewController *thisMap = (MapViewController *)[[UIApplication sharedApplication]  delegate];
    detailViewController *detailView = [[detailViewController     alloc]initWithNibName:@"detailViewController" bundle:nil];
    [thisMap switchViews:self.view toView:dvc.view];
}

这是一种非常基本的视图切换方法,对我来说效果很好。

于 2011-10-13T23:22:24.167 回答
0

您没有显示所有代码。但我想,你只是忘记初始化 self.detailViewController。

尝试将其添加到您的 viewDidLoad 方法中:

self.detailViewController = [[[DetailViewController alloc]init]autorelease];
于 2010-12-29T11:05:21.740 回答
0

detailViewController 不是未初始化吗?您没有显示所有代码,但我相信您在准备视图和推送视图时可能会有些混乱。

为什么将 detailViewController 声明为 IBOUTlet?

另外,我认为您可能希望/打算在不在此控制器中的 detailViewController 上执行此操作:

[self.navigationController setToolbarHidden:YES animated:NO];
于 2010-06-15T05:25:55.007 回答