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

detailViewController が初期化されていませんか? すべてのコードを表示しているわけではありませんが、ビューの準備とプッシュが少し混乱している可能性があると思います。

なぜdetailViewControllerをIBOUTletとして宣言しているのですか?

また、このコントローラーではなく、detailViewController でこれを実行したい/意図している可能性があると思います。

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

すべてのコードを表示するわけではありません。しかし、おそらく、self.detailViewController の初期化を忘れているだけです。

これを viewDidLoad メソッドに追加してみてください:

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