Objective c 为什么使用NSNotification参数
这是main.m中的代码Objective c 为什么使用NSNotification参数,objective-c,nsnotification,Objective C,Nsnotification,这是main.m中的代码 [[NSNotificationCenter defaultCenter]addObserver:logger selector:@selector(zoneChange:) name:NSSystemTimeZoneDidChangeNotification object:nil]; 下面是.h文件中的代码 -(void)zoneChange:(NSNotification *)note; 有人能告诉我为什么zoneChange方法将NSNotification作
[[NSNotificationCenter defaultCenter]addObserver:logger selector:@selector(zoneChange:) name:NSSystemTimeZoneDidChangeNotification object:nil];
下面是.h文件中的代码
-(void)zoneChange:(NSNotification *)note;
有人能告诉我为什么zoneChange方法将NSNotification作为参数吗?
当我们试图声明这个方法将被上面main.m文件中提到的方法使用时,我们如何知道这个方法采用了什么参数
我还对类引用做了一些研究,发现选择器参数是这样的
选择器,指定接收方发送notificationObserver以通知其通知发布的消息。notificationSelector指定的方法必须只有一个参数(NSNotification的实例)
请解释一下。谢谢好吧,这就是api所说的
- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender
其中notificationSelector是一个
选择器,用于指定接收方接收的消息
发送notificationObserver以通知其通知发布。
notificationSelector指定的方法必须只有一个
一个参数(NSNotification的实例)
所以,大多数时候,你会去阅读苹果公司提供的文档,看看你的选择器可以使用什么样的参数
来源:好吧,这就是api所说的
- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender
其中notificationSelector是一个
选择器,用于指定接收方接收的消息
发送notificationObserver以通知其通知发布。
notificationSelector指定的方法必须只有一个
一个参数(NSNotification的实例)
所以,大多数时候,你会去阅读苹果公司提供的文档,看看你的选择器可以使用什么样的参数
来源:假设您有一个具有两个表视图的控制器:
@interface MyController : NSViewController <NSTableViewDelegate>
@property(nonatomic,weak) IBOutlet NSTableView *tableView1;
@property(nonatomic,weak) IBOutlet NSTableView *tableView2;
@end
假设您有一个具有两个表视图的控制器:
@interface MyController : NSViewController <NSTableViewDelegate>
@property(nonatomic,weak) IBOutlet NSTableView *tableView1;
@property(nonatomic,weak) IBOutlet NSTableView *tableView2;
@end
那么这是否意味着我真的不必知道他们为什么需要NSNotification参数,只需根据他们需要的参数编写代码?@user3090658“他们”不需要它。您可以这样做,因为通知至少包含通知
对象
和用户信息
属性。这就是为什么目标操作机制总是向目标操作发送sender
。@user312567我真的不明白您的意思,请您进一步解释一下好吗?请记住,您正在定义方法,因此NSNotification是为您发送的。你不必使用它。事实上,如果不需要通知对象,只需执行@selector(zoneChange)即可。user3125367和user3090658。。我们在什么地方见过面吗?你看起来很熟悉。。。提示提示、眨眼、轻推……这是否意味着我真的不必知道他们为什么需要NSNotification参数,只需根据他们需要的参数编写代码?@user3090658“他们”不需要它。您可以这样做,因为通知至少包含通知对象
和用户信息
属性。这就是为什么目标操作机制总是向目标操作发送sender
。@user312567我真的不明白您的意思,请您进一步解释一下好吗?请记住,您正在定义方法,因此NSNotification是为您发送的。你不必使用它。事实上,如果不需要通知对象,只需执行@selector(zoneChange)即可。user3125367和user3090658。。我们在什么地方见过面吗?你看起来很熟悉。。。暗示暗示,眨眼眨眼,轻推轻推..对我有用。。谢谢你对我有用。。谢谢+1