我正在使用推送通知的iphone应用程序。我的问题是当我收到推送通知而不创建该类的实例而不使用静态方法时如何从classB调用函数?
非常感谢:)
答案 0 :(得分:1)
您需要在接收推送通知的对象中保留对classB的引用:
// The header file of the class that receives the notification
@class classB;
@interface MyNotifiedClass : NSObject
{
classB *_classB;
}
@property (retain, nonatomic, readwrite) classB *classB;
// The implementation file of the class that receives the notification
@implementation MyNotifiedClass
....
@synthesize classB = _classB;
- (void)theMethodThatReceivesTheNotification:(whatever)
{
[_classB doSomethingNowPlease];
}
显然,您需要在此类中设置classB
的实例才能生效:
// Someplace outside both classes (assuming _classB points to an instance of classB
// and _myNotifiedClass points to an instance of MyNotifiedClass)
[_myNotifiedClass setClassB:_classB];
答案 1 :(得分:0)
没有实例化它就无法调用类的实例方法。您的解决方案是调用类方法或classB
可以使用单例初始值设定项。