将MKMapType变量从FlipsideViewController中的UISegmentedControl传递给MainViewController

时间:2011-06-02 00:36:29

标签: objective-c methods delegates uiviewcontroller mkmapview

我无法将UISegmentedControl的索引从FlipSideViewController.m传递到我的MainViewController.m,它保存着我的MKMapView。这是我的代码:

MainViewController.h

 @interface MainViewController : UIViewController <FlipsideViewControllerDelegate, MKMapViewDelegate> {
   MKMapView *mapView;
 }

 @property (nonatomic, retain) UISegmentedControl *mapType;

 @property (nonatomic, retain) IBOutlet MKMapView *mapView;
 - (IBAction)showInfo:(id)sender;
 @end

FlipSideViewController.h

@protocol FlipsideViewControllerDelegate;

@interface FlipsideViewController : UIViewController {
  id <FlipsideViewControllerDelegate> delegate;
  IBOutlet UISegmentedControl *mapType_;
}

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
  - (IBAction)done:(id)sender;

@property (nonatomic, retain) UISegmentedControl *mapType_;
@end

@protocol FlipsideViewControllerDelegate
    - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
    - (void)flipsideViewControllerSelectionChangedToIndex:(int)index;
@end

FlipSideViewController.m

 - (IBAction)changeView {
  [delegate flipsideViewControllerSelectionChangesToIndex: mapType_.selectedSegmentIndex];
  }

MainViewController.m

- (void)flipsideViewControllerSelectionChangedToIndex:(int)index {
  if ( index == 0 )mapView.mapType = MKMapTypeStandard;
  if ( index == 1 )mapView.mapType = MKMapTypeHybrid;
  if ( index == 2 )mapView.mapType = MKMapTypeSatellite;
 }

我的问题是,在我的模拟器中,当我单击UISegmentedControl中的任何段时,应用程序将关闭。控制台显示抛出此错误:

-[FlipsideViewController changeView:]: unrecognized 
 selector sent to instance 0x6d43f30
2011-06-01 19:50:31.055 GermTracker2[893:207] *** 
Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[FlipsideViewController changeView:]:   
unrecognized selector sent to instance 0x6d43f30'

1 个答案:

答案 0 :(得分:0)

你的FlipSideViewController.h中有一个双@end。尝试在@end

之后删除- (IBAction)done:(id)sender;