Xcode 从另一个 .h 文件调用函数来更新其状态
我有两个 UIView 并链接到以下文件
1.FirstViewController.h和.m
2. MapTypeOption.h 和 .m
FirstViewController 链接到带有导航控件的 MapTypeOption
我想执行以下任务
使用 MapTypeOption 处的 UI Segment 控件进行更改
FirstViewController 中的 Google 地图类型,
在 FirstViewController.h 中,我有一个函数,如下
- (void)ChangeMapType:(int )SelectIndex
所示
-(void)ChangeMapType:(int )SelectIndex
{
switch (SelectIndex)
{
case 0:
MainMapView.mapType = MKMapTypeStandard;
break;
case 1:
MainMapView.mapType = MKMapTypeSatellite;
break;
case 2:
MainMapView.mapType = MKMapTypeHybrid;
break;
default:
MainMapView.mapType = MKMapTypeStandard;
break;
}
}
。
#import "FirstViewController.h"
@class FirstViewController;
....
- (IBAction)updatemaptype:(id)sender
{
FirstViewController *newFirstViewControllerobj=[[FirstViewController alloc] init];
[newFirstViewControllerobj ChangeMapType:MapTypeSegment.selectedSegmentIndex];
}
因此 不同
MapTypeOption 视图中的段 FirstViewController 中没有任何更改
I have two UIView and link to the following files
1. FirstViewController.h and .m
2. MapTypeOption.h and .m
FirstViewController is link to MapTypeOption with Navigation control
I would like to perform the following task
Use a UI Segment Control at MapTypeOption to change
the Google map type in FirstViewController
so in FirstViewController.h I have a function as follow
- (void)ChangeMapType:(int )SelectIndex
my FirstViewController.m has a function as follow
-(void)ChangeMapType:(int )SelectIndex
{
switch (SelectIndex)
{
case 0:
MainMapView.mapType = MKMapTypeStandard;
break;
case 1:
MainMapView.mapType = MKMapTypeSatellite;
break;
case 2:
MainMapView.mapType = MKMapTypeHybrid;
break;
default:
MainMapView.mapType = MKMapTypeStandard;
break;
}
}
in MapTypeOption.m I have the following
#import "FirstViewController.h"
@class FirstViewController;
....
- (IBAction)updatemaptype:(id)sender
{
FirstViewController *newFirstViewControllerobj=[[FirstViewController alloc] init];
[newFirstViewControllerobj ChangeMapType:MapTypeSegment.selectedSegmentIndex];
}
I can compile and run my program (with simulator) but even I select a different
segment at MapTypeOption view nothing is changed in FirstViewController
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要在 ChangeMapType 中调用 [view setNeedsDisplay] 来更新视图。
You probably need to call [view setNeedsDisplay] in ChangeMapType to cause the view to update.