0

しばらくの間、注釈ボタンを使用して別の mapView に切り替える方法を理解しようとしています。私が取り組んでいるアプリは、MapBox - マップを使用しています。それらが提供する例を確認しましたが、プログラムで2つのマップを切り替えることは常にタブバーを介して行われます(これは私が使用したい場合ではありません)。私はストーリーボードで作業しており、インターフェイスビルダーでセグエを作成する方法をよく理解していましたが、マップビューのプログラムで統合されたボタンで管理していないと思います。両方のヘッダー ファイルで「id」を開始し、Identity Inspector でも宣言しました。

これはコードの一部であり、メイン ビュー コントローラー (ViewController) に注釈を付けて RMMMapView を実装すると、完全に機能します。

- (void)viewDidLoad{

[super viewDidLoad];

RMMapBoxSource *onlineSource = [[RMMapBoxSource alloc] initWithMapID:(([[UIScreen    mainScreen] scale] > 1.0) ? kRetinaMapID : kNormalMapID)];

_mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:onlineSource];

_mapView.tileSource = [[RMMapBoxSource alloc] initWithMapID:(([[UIScreen mainScreen] scale] > 1.0) ? kRetinaMapID : kNormalMapID)];
_mapView.centerCoordinate = CLLocationCoordinate2DMake(0,0);

 _mapView.adjustTilesForRetinaDisplay = YES;
_mapView.zoom = 4;

_mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

[self.view addSubview:_mapView];
_mapView.showsUserLocation = YES;

[_mapView setConstraintsSouthWest:[_mapView.tileSource latitudeLongitudeBoundingBox].southWest
                            northEast:[_mapView.tileSource latitudeLongitudeBoundingBox].northEast];
RMPointAnnotation *annotation = [[RMPointAnnotation alloc] initWithMapView:_mapView
                                                                coordinate:_mapView.centerCoordinate andTitle:@"Hello, world!"];
[_mapView addAnnotation:annotation];
}

これは、ViewController - main ViewController から LowContentMap viewController を呼び出そうとする部分です。

- (void) prepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender {
if ([segue.identifier isEqualToString:@"Hello, world!"]) {
    //LowContentMap *lowContentMap = segue.destinationViewController;

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    LowContentMap *lowContentMap = [storyboard instantiateViewControllerWithIdentifier:@"lowContentMap"];
    lowContentMap.lcm = _vc;
}}

これは、入力する必要があるコードの一部です。

- (void)mapView:(RMMapView *)mapView annotationView:(RMPointAnnotation *)annotation calloutAccessoryControlTapped:(UIControl *)control{
[self performSegueWithIdentifier:@"ShowSomeViewController" sender:annotation];
}

誰かが問題を解決しようとするなら、それは本当に素晴らしいことです. Noa と Kronos の間の議論に従いました: Segue を 使用して詳細ビュー コントローラーをセットアップします が、「id」の部分は私が間違っていると思います。前もって感謝します。

4

1 に答える 1

0

1.あなたの問題は、別のviewControllerを表示する方法がわからないことだと思います

「View Controller Programming Guide」、特に「Presenting View Controllers from Other View Controllers」の部分をよく読む必要があります。

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html

また、ViewController の使用方法を示す素晴らしい WWDC ビデオもチェックすることをお勧めします。

2. viewController の作成方法と表示方法

それを行うには多くの方法があります。たとえば、ストーリーボードを使用してviewControllerを作成および表示し、子コントローラーでプロトコルを定義し、「performSegueWithIdentifier」をオーバーライドしてデリゲートを設定し、プロトコルを実装してVCを却下します。

ただし、あなたの場合、すべてをプログラムで行うのが理にかなっているようです。したがって、次のことを行う必要があります。

a) アクションを追加する適切な場所を見つける

b) ビュー コントローラを割り当てて初期化します。

MyController *myController = [[MyController alloc] init];
// setup as required, there should be at least a delegate (being able to dismiss the view)
myController.delegate = self;

ストーリーボードで viewController を設計した場合は、代わりに次の alloc/init ルーチンを使用することをお勧めします。

MyController *myController = [[UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil] instantiateViewControllerWithIdentifier:@"MyController"];
myController.delegate = self;

c) 新しいビュー コントローラーを表示します。 これは、navigationController があるかどうかによって異なります。

[self.navigationController pushViewController:myController animated:YES];

...またはモーダルに表示する場合:

[self presentViewController:myController animated:YES completion:NULL];

d) 完了したら却下します。 他のコントローラーが何をするにしても、それが完了したら、デリゲートに通知する必要があります (独自のプロトコルを実装してください!) 完了し、破棄する必要があります。デリゲートは、「myController」を作成 (割り当て/初期化) した元の viewController です。

// this method should be defined in a protocol and implemented in the vc that created (and owns) the child view controller
// typically, this is the parent view controller 
- (void)done {
    [self dismissViewControllerAnimated:YES completion:NULL];
}

navigationController を使用した場合、-dismissViewControllerAnimated: ではありませんが、

[self.navigationController popViewControllerAnimated:YES];

これが物事を明確にするのに役立つことを願っています

于 2013-07-17T09:47:04.230 に答える