从弹出控制器调用模态视图上的方法
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个常见问题,而且很容易解决。解决方案只是在 .m 文件中进行导入。如果您需要在 .h 文件中了解类型,只需使用前向声明即可。
就这么简单。
编辑:更彻底的解释:
通常在 .h 文件中,不需要知道类的方法和属性。您需要做的就是告诉编译器有一个名为
ClassName
的类。此时编译器不需要了解有关该类的任何其他信息。在 .m 文件中,您需要知道该类的方法和属性,否则您将无法使用它。因此,在 .m 文件中导入该类。需要明确的是:
这称为前向声明。您可以通过谷歌搜索以了解更多信息或阅读有关编程的入门书籍。这是一个非常基本的编程概念,学习它很重要。
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.
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:
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.