0

プッシュ通知付きのiPhoneアプリに取り組んでいます。私の質問は、クラスBのインスタンスを作成したり、静的メソッドを使用したりせずにプッシュ通知を受け取ったときに、クラスBから関数を呼び出す方法です。

どうもありがとう :)

4

2 に答える 2

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];
于 2012-05-04T09:36:16.500 に答える
0

クラスのインスタンスメソッドをインスタンス化せずに呼び出す方法はありません。あなたの解決策は、クラスメソッドを呼び出すか、classBシングルトン初期化子を持つことができます。

于 2012-05-04T09:27:16.247 に答える