从弹出控制器调用模态视图上的方法

发布于 2024-10-28 19:22:32 字数 446 浏览 7 评论 0原文

我有一个 iPad 应用程序,其中包含 splitviewcontroller - 从 splitview 的详细视图中,我打开一个 modalviewcontroller(NearbyViewController),其中有一个按钮,显示带有选择器的弹出框(RadiusViewController)。这工作得很好,但是当我在选择器中选择一个值时,我想调用模态视图控制器上的方法,但我不知道如何做到这一点?

我的“NearbyViewController”导入“RadiusViewController.h”,因为我访问“RadiusViewController”中的某些数据,但我还需要能够将数据从RadiusViewController发送回NearbyViewController,但是如果我在“RadiusViewController”中导入NearbyViewController.h文件RadiusView 然后我得到编译错误,因为他们试图互相导入。

I have an iPad application which consists of a splitviewcontroller - From the detailview of the splitview i open a modalviewcontroller(NearbyViewController) which has a button that shows a popover(RadiusViewController) with a picker. This works just fine, but when i select a value in the picker i want to call a method on the modalview controller, but i can't figure out how to do this?

My "NearbyViewController" imports the "RadiusViewController.h" because i access certain data in the "RadiusViewController", but i also need to be able to send data from the RadiusViewController back to NearbyViewController, but if i import the NearbyViewController.h file in the RadiusView then i get compilation errors due to them trying to import eachother.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

无畏 2024-11-04 19:22:32

这是一个常见问题,而且很容易解决。解决方案只是在 .m 文件中进行导入。如果您需要在 .h 文件中了解类型,只需使用前向声明即可。

@class ClassName;

就这么简单。

编辑:更彻底的解释:

通常在 .h 文件中,不需要知道类的方法和属性。您需要做的就是告诉编译器有一个名为 ClassName 的类。此时编译器不需要了解有关该类的任何其他信息。在 .m 文件中,您需要知道该类的方法和属性,否则您将无法使用它。因此,在 .m 文件中导入该类。

需要明确的是:

// SomeClass.h
@class ClassName;

// SomeClass.m
#import "ClassName.h"

这称为前向声明。您可以通过谷歌搜索以了解更多信息或阅读有关编程的入门书籍。这是一个非常基本的编程概念,学习它很重要。

This is a common problem and it's very easy to solve. The solution is simply to make the imports in the .m files instead. If you need the type to be known in the .h file, you simply use forward declaration.

@class ClassName;

It's as simple as that.

EDIT: A more thorough explanation:

Generally in the .h file the methods and properties of the class doesn't need to be known. All you need to do is tell the compiler that there is a class named ClassName. The compiler doesn't need to know anything else about the class at that point. In the .m file you will need to know the methods and properties of that class or you will not be able to use it. So in the .m file you import the class.

Just to be clear:

// SomeClass.h
@class ClassName;

// SomeClass.m
#import "ClassName.h"

This is called forward declaration. You can google it to learn more or read an introductory book on programming. It's a very basic programming concept and it's important that you learn it.

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