誰かがNSNotifcationCenterのオブジェクトプロパティを使用する方法を教えてください。私はそれを使用してセレクタメソッドに整数値を渡すことができるようにしたい。NSNotificationcenterのオブジェクトプロパティを使用する方法
これは、UIリスナーで通知リスナーを設定した方法です。整数値を渡したいので、nilを何に置き換えるべきか分かりません。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveEvent:) name:@"myevent" object:nil];
- (void)receiveEvent:(NSNotification *)notification {
// handle event
NSLog(@"got event %@", notification);
}
私はこのような別のクラスからの通知をディスパッチします。この関数には、indexという名前の変数が渡されます。私が何らかの理由で通知を出して欲しいのは、この価値です。
-(void) disptachFunction:(int) index
{
int pass= (int)index;
[[NSNotificationCenter defaultCenter] postNotificationName:@"myevent" object:pass];
//[[NSNotificationCenter defaultCenter] postNotificationName:<#(NSString *)aName#> object:<#(id)anObject#>
}
同時に心が働きます。 :) –
私はあなたの選択をしました。私がやらなければならなかった唯一のことは、辞書の周りに自動解放プールをラップすることでした。 – dubbeat
(ああ、私の解決策はMatthewのものと同じですが、ちょっと早くSubmitをクリックするだけでした) – gavinb