Xcode 从另一个 .h 文件调用函数来更新其状态

发布于 2025-01-05 09:36:50 字数 1157 浏览 2 评论 0原文

我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筑梦 2025-01-12 09:36:50

您可能需要在 ChangeMapType 中调用 [view setNeedsDisplay] 来更新视图。

You probably need to call [view setNeedsDisplay] in ChangeMapType to cause the view to update.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文