0

アプリケーションで Split View Controller を使用しています。左側のパネル (マスター ビュー コントローラー) にはホテルのリストを含むテーブル ビューがあり、右側の詳細ビュー コントローラーには場所を表示するための MapView が含まれています。最初は、アプリケーションの起動時に現在の場所を表示しています。次に、テーブル ビューから値を選択した後、ホテルの場所をマップに表示しようとしています。残念ながら、適切な緯度と経度の値を渡しても、地域を変更することはできず、場所にまったく変化が見られません。

これが理解のための実装コードのスニペットです!!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *hotelInfo = [self.hotelDetails objectAtIndex:indexPath.row];
    NSString *placeLatitude = [hotelInfo valueForKey:@"Latitude"];
    NSString *placeLongitude = [hotelInfo valueForKey:@"Longitude"];
    CLLocationCoordinate2D location;
    location.latitude = [placeLatitude doubleValue];
    location.longitude = [placeLongitude doubleValue];
    [self setMapViewLocation:location];
}

-(void)setMapViewLocation:(CLLocationCoordinate2D)location
{
    [[MapView sharedMapInstance] updateMapViewWithLocation:location];
}

MapView の地域を設定するために場所の値を利用する方法は次のとおりです。

-(void)updateMapViewWithLocation:(CLLocationCoordinate2D)location
{
//    [self.locationManager startUpdatingLocation];
//    NSLog(@"latitude:%f,longitude:%f",location.latitude,location.longitude);
//    
//    MKCoordinateRegion region;
//    region.center = location;
//    
//    MKCoordinateSpan span;
//    span.latitudeDelta  = 0.015;
//    span.longitudeDelta = 0.015;
//    region.span = span;
//    NSLog(@"Center (%f, %f) span (%f, %f) user: (%f, %f)| IN!", region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta, location.latitude, location.longitude);
//
//    [self.locationView setRegion:region animated:YES];
//    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 800, 800);
//    MKCoordinateSpan span = {.latitudeDelta =  0.015, .longitudeDelta =  0.015};
    MKCoordinateRegion region;
    region.center = location;
    [self.locationView setRegion:[self.locationView regionThatFits:region] animated:NO];
}

コメント行は、私が試したソリューションのさまざまな組み合わせですが、何も機能していないようです。

注:ログで正しい値を見つけたので、座標値を正確に渡すことができます。

誰かが私を助けてくれませんか、ありがとう:)

4

1 に答える 1

1

正しい方向に私を指摘してくれた Mr.Anna に感謝します。シングルトンを介して詳細ビュー クラスにアクセスするか、クラス オブジェクトをインスタンス化する代わりに、UISplitViewController の viewControllers配列を使用して、detailView にアクセスし、変更を加えます。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *hotelInfo = [self.hotelDetails objectAtIndex:indexPath.row];
    NSString *placeLatitude = [hotelInfo valueForKey:@"Latitude"];
    NSString *placeLongitude = [hotelInfo valueForKey:@"Longitude"];
    CLLocationCoordinate2D location;
    location.latitude = [placeLatitude doubleValue];
    location.longitude = [placeLongitude doubleValue];
    [self setMapViewLocation:location];
}

-(void)setMapViewLocation:(CLLocationCoordinate2D)location
{
    self.dvc = [self.splitViewController.viewControllers lastObject];
    MKCoordinateRegion region;
    region.center = location;
    MKCoordinateSpan span;
    span.latitudeDelta  = 0.015;
    span.longitudeDelta = 0.015;
    region.span = span;
    [self.dvc.locationView setRegion:[self.dvc.locationView regionThatFits:region] animated:NO];
}

それが役立つことを願っています、ありがとう:)

于 2015-04-16T08:10:49.573 に答える