开发者

How to create a method for posting a notification in Objective-C?

开发者 https://www.devze.com 2022-12-20 07:23 出处:网络
How to create a method for posting a notification through the NSNotificationCenter and then call the method through applicationDidFinishLauching main method without any (IBAction) . I just wanted to s

How to create a method for posting a notification through the NSNotificationCenter and then call the method through applicationDidFinishLauching main method without any (IBAction) . I just wanted to send only a message.I also dont want the postNotification to be placed in applicationDidFinishLaunching method.

-(void)applicationDidFinishLaunching
{

 event=[[SomeCl开发者_Python百科ass alloc]init];

}

-(void)sendEvent:(id)sender
{
     postNotificationName:... object:---
}

Now i where i need to call this sendEvent method in my program. How to do it?


The -postNotification method on NSNotificationCenter is what you're looking for:

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
   // ...
   [self postNotification];
}

- (void)postNotification
{
   [[NSNotificationCenter] defaultCenter] postNotification:@"Notification"];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消