将UISegmentedControl值从Utility应用程序中的FlipSideViewController传递到mainviewcontroller ... [英] Passing UISegmentedControl values from FlipSideViewController in an Utility application to the mainviewcontroller…
问题描述
例如,如果flipsideviewcontroller中的segmentedcontrol发生变化,我希望Mainviewcontroller中的maptype从satellite变为hybrid?我究竟做错了什么?基本上,我希望mainviewcontroller对flipsideviewcontroller中所做的更改作出反应!!!
For example, I want the maptype in the Mainviewcontroller to change from satellite to hybrid if the segmentedcontrol in the flipsideviewcontroller changes? What am i doing wrong? Basically, I want the mainviewcontroller to react to the changes made in the flipsideviewcontroller!!!
FlipsideViewController.h
FlipsideViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKMapView.h>
@protocol FlipsideViewControllerDelegate;
@interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
IBOutlet UISegmentedControl *mapType_;
}
@property (nonatomic, retain) UISegmentedControl *mapType_;
@end
MainViewController.h
MainViewController.h
@interface MainViewController : UIViewController <XXXX> {
IBOutlet UISegmentedControl *mapType;
}
@property (nonatomic, retain) UISegmentedControl *mapType;
@end
MainViewController.m
MainViewController.m
-(void)viewDidLoad {
if(mapType.selectedSegmentIndex==0){
mapView.mapType=MKMapTypeStandard;
}
else if (mapType.selectedSegmentIndex==1){
mapView.mapType=MKMapTypeSatellite;
}
else if (mapType.selectedSegmentIndex==2) {
mapView.mapType = MKMapTypeHybrid;
}
}
有关如何实现这一目标的任何想法?我究竟做错了什么?非常感谢答案!谢谢!
Any ideas of how to make this possible? What am i doing wrong? Would really appreciate an answer! Thanks!
如何实现委托方法(正如phix23所回答的那样)......?
How do I implement the delegate method (as phix23 answered)...?
推荐答案
(1)通过这种新方法扩展 FlipsideViewControllerDelegate
协议:
(1) Extend theFlipsideViewControllerDelegate
protocol by this new method:
-(void)flipsideViewControllerSelectionChangedToIndex:(int)index;
(2)在 FlipsideViewController中添加IBAction
为了重新分配分段控件的ValueChanged-Event:
(2) Add an IBAction in FlipsideViewController
in order to resond to the ValueChanged-Event of the segmented control:
-(IBAction) valueChanged {
[delegate flipsideViewControllerSelectionChangedToIndex: mapType_.selectedSegmentIndex];
}
(3)在 MainViewController
实现委托方法:
(3) In MainViewController
implement the delegate method:
-(void)flipsideViewControllerSelectionChangedToIndex:(int)index {
if (index == 0) mapView.mapType = MKMapTypeStandard;
if (index == 1) mapView.mapType = MKMapTypeSatellite;
if (index == 2) mapView.mapType = MKMapTypeHybrid;
}
并删除 MainViewController中的IBOutlet
!
这篇关于将UISegmentedControl值从Utility应用程序中的FlipSideViewController传递到mainviewcontroller ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!