将 UISegmentedControl 值从实用程序应用程序中的 FlipSideViewController 传递到 mainviewcontroller;
例如,如果 FlipsideViewController 中的 SegmentedControl 发生变化,我希望 MainViewController 中的地图类型从卫星更改为混合?我做错了什么?基本上,我希望 mainviewcontroller 对 Flipsideviewcontroller 中所做的更改做出反应!
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
@interface MainViewController : UIViewController <XXXX> {
IBOutlet UISegmentedControl *mapType;
}
@property (nonatomic, retain) UISegmentedControl *mapType;
@end
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;
}
}
关于如何实现这一点有什么想法吗?我做错了什么?非常感谢您的回答!谢谢!
我如何实现委托方法(如 phix23 回答)...?
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
#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
@interface MainViewController : UIViewController <XXXX> {
IBOutlet UISegmentedControl *mapType;
}
@property (nonatomic, retain) UISegmentedControl *mapType;
@end
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!
How do I implement the delegate method (as phix23 answered)...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(1) 通过此新方法扩展
FlipsideViewControllerDelegate
协议:(2) 在
FlipsideViewController
中添加 IBAction,以便响应分段控件的 ValueChanged-Event:(3 ) 在
MainViewController
中实现委托方法:并删除
MainViewController
中的IBOutlet!(1) Extend the
FlipsideViewControllerDelegate
protocol by this new method:(2) Add an IBAction in
FlipsideViewController
in order to resond to the ValueChanged-Event of the segmented control:(3) In
MainViewController
implement the delegate method:And delete the IBOutlet in
MainViewController
!