0

こんにちは、

私のViewController.mi´では、次のように「viewDidLoad」にNSNotificationを追加しました。

        [[NSNotificationCenter defaultCenter] addObserver:self
                                    selector:@selector(pageControlChanged:) 
                                    notificationName:@"ScrollViewDidEnd"
   object:nil];

次に、画像をスクロールできるカスタムscrollViewクラス「MyScrollView」を用意しました。「scrollViewDidEndDecelerating:(UIScrollView *)scrollView {..」メソッドが呼び出されたときに、そこにpostNotificationを追加しました。

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScrollViewDidEnd" object:nil];
}
- (void) pageControlChanged:(NSNotification*)notification{
    NSLog(@"pagecontrol: %@", notification);

}

プロジェクトをコンパイルすると、エラーが発生し、アプリがクラッシュします。コンソール出力:「addObserver:selector:notifcatonName:object:」メソッドが見つかりません。

ですから、これが私の最初のNSNotificationの使用法であり、ここで助けを得るのは素晴らしいことです。御時間ありがとうございます。ヨシュ

4

1 に答える 1

1

あなたが探している方法は次のとおりです。

- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender

name:(ではなく、に注意してくださいnotificationName:

したがって、コードは次のようになります。

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(pageControlChanged:)
                                             name:@"ScrollViewDidEnd"
                                           object:nil];
于 2010-08-02T09:38:15.080 に答える