プッシュ通知付きのiPhoneアプリに取り組んでいます。私の質問は、クラスBのインスタンスを作成したり、静的メソッドを使用したりせずにプッシュ通知を受け取ったときに、クラスBから関数を呼び出す方法です。
どうもありがとう :)
プッシュ通知付きのiPhoneアプリに取り組んでいます。私の質問は、クラスBのインスタンスを作成したり、静的メソッドを使用したりせずにプッシュ通知を受け取ったときに、クラスBから関数を呼び出す方法です。
どうもありがとう :)
プッシュ通知を受信するオブジェクト内から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];
クラスのインスタンスメソッドをインスタンス化せずに呼び出す方法はありません。あなたの解決策は、クラスメソッドを呼び出すか、classB
シングルトン初期化子を持つことができます。