macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

notificationWithName:object:userInfo:

名前とオブジェクトと追加情報で通知を作って返します
+(id)notificationWithName:(NSString *)aName:
             object:(id)anObject:
             userInfo:(NSDictionary *)userInfo:

解説

名前とオブジェクトと追加情報で通知を作って返します。
anObjectとuserInfoは、nilかもしれません。

返り値

( id )

通知

引数

( NSString * )aName

名前

( id )anObject

オブジェクト

( NSDictionary * )userInfo

ユーザーインフォ

クラス

NSNotification

Class Methods

使用可能

10.0

参照

+notificationWithName:object:
- postNotificationName:object:userInfo:(NSNotificationCenter)

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
//デフォルトの通知センターをnCenterに
NSNotificationCenter *nCenter =[NSNotificationCenter defaultCenter];
//通知を作る
NSNotification *notifi = [NSNotification notificationWithName:@"NSWindowDidResizeNotification" object:nil userInfo:nil];

//nCenterにオブザーバーを加える
[nCenter addObserver:self//これを呼び出す
            selector:@selector(windowResize:) //呼び出されるメソッド
            name:@"NSWindowDidResizeNotification" //ウインドウがリサイズされたら
            object:nil];
//nCenterにオブザーバーを加える
[nCenter addObserver:myOutlet//NotifiObjectクラス
            selector:@selector(windowResize:) //呼び出されるメソッド
            name:@"NSWindowDidResizeNotification" //ウインドウがリサイズされたら
            object:nil];

//通知センターに通知を送る
[nCenter postNotification:notifi];
}
//通知されたときのメソッド
- (void)windowResize:(NSNotification *)notification
{
NSLog(@"MyObject");
}
@end