我目前正试图在另一个viewcontoller(BackgroundMapViewController)的分段控件的帮助下更改我的地图的maptype(来自MapsViewController)。我使用页面卷曲来查看带有segmentedcontol的viewcontoller(就像iphone上的地图应用程序一样) 问题是我不知道如何将我的BackgroundMapViewController中的信息传递给我的MapsviewController。 (可能是代表团?)我知道你使用委托将一个对象的“工作”给另一个对象,但我不知道如何在这里使用它。 如果有人可以帮我解决我的问题,我真的很感激
(您可以在此处查看用户界面的图片: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
答案 0 :(得分: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];