0

我目前正在尝试在另一个视图控制器(BackgroundMapViewController)的分段控件的帮助下更改我的地图的地图类型(来自 MapsViewController)。我使用 page curl 来查看带有分段控件的 viewcontoller(就像 iphone 上的地图应用程序)问题是我不知道如何将信息从我的 BackgroundMapViewController 传递到我的 MapsviewController。(可能有委托??)我知道你使用委托将一个对象的一些“工作”交给另一个对象,但我不知道我应该如何在这里使用它。如果有人可以帮助我解决我的问题,我将不胜感激

(你可以在这里看到 UI 的图片:http: //i50.tinypic.com/169masx.png

MapsBackgrounsViewController.h

    @interface MapBackgroundViewController : UIViewController{
    IBOutlet UISegmentedControl *segmentedControl;
    MKMapType mapType;
    }

    @property (nonatomic) IBOutlet UISegmentedControl *segmentedControl;
    @property(nonatomic) MKMapType mapType;
    - (IBAction)segmentedControllChanged:(id)sender;

MapsViewController.m

    @interface MapBackgroundViewController ()
    @end

    @implementation MapBackgroundViewController
    @synthesize segmentedControl, mapType;

    - (IBAction)segmentedControllChanged:(id)sender {

    if (segmentedControl.selectedSegmentIndex == 0) {
        mapType = MKMapTypeStandard;
    }else if (segmentedControl.selectedSegmentIndex == 1) {
        mapType = MKMapTypeSatellite;
    } else if (segmentedControl.selectedSegmentIndex == 2) {
       mapType = MKMapTypeHybrid;
    }


    [self dismissModalViewControllerAnimated:YES];

}

MapsViewController.h

   @interface MapsViewController : UIViewController<MKMapViewDelegate,   UISearchBarDelegate>{
   @private
   IBOutlet MKMapView *map;
   //some other outlet
   }

   @property (nonatomic, retain) IBOutlet MKMapView *map;
   @property (nonatomic, retain) IBOutlet  UISearchBar *searchBar;
   //some other actions and properties
4

1 回答 1

0

不需要存储mapType,直接在地图视图中设置即可:

@interface MapBackgroundViewController ()
@end

@implementation MapBackgroundViewController
@synthesize segmentedControl, mapViewController; // Connect mapViewController to your other view controller

- (IBAction)segmentedControllChanged:(id)sender {

if (segmentedControl.selectedSegmentIndex == 0) {
    self.mapViewController.map.mapType = MKMapTypeStandard;
}else if (segmentedControl.selectedSegmentIndex == 1) {
    self.mapViewController.map.mapType = MKMapTypeSatellite;
} else if (segmentedControl.selectedSegmentIndex == 2) {
   self.mapViewController.map.mapType = MKMapTypeHybrid;
}


[self dismissModalViewControllerAnimated:YES];
于 2012-05-19T14:11:18.647 回答