我在调用类中使用前向声明。
ClassTwo 中的.h 文件
@class ClassOne
@property(nonatomic,retain) ClassOne *class_One;
.m 文件
@synthesize class_One;
然后我尝试在ClassOne中调用这个方法
[self.class_One callingThisMethodFromClassTwo];
另一方面,如果我在 ClassOne 中创建一个共享实例并将其用作类方法,它就可以工作
[[ClassOne Shared] nowItWorks];
对不起,如果这是一个愚蠢的问题,我是新手
最佳答案
尝试分配 class_One 实例并将 #import "ClassOne.h"
添加到 classtwo.m
顶部的 header 中
self.class_One= [[ClassOne alloc]init];
[self.class_One callingThisMethodFromClassTwo];
关于ios - 无法调用另一个类中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14487324/