首先上代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0, 0, 400, 60)];
[button addTarget:self action:@selector(buttonDown) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Post Notification" forState:UIControlStateNormal];
[self.view addSubview:button];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionNotification:)
name:kNotificationName object:nil];
}
- (void) actionNotification: (NSNotification*)notification
{
NSString* message = notification.object;
NSLog(@"%@",message);
sleep(5);
NSLog(@"Action Notification Fin

本文介绍了iOS开发中NSNotification的同步和异步处理方式,通过代码示例展示了如何在不同线程中执行通知事件处理,以及如何利用`performSelector:`和`performSelectorInBackground:`实现异步发送通知。
最低0.47元/天 解锁文章
2023

被折叠的 条评论
为什么被折叠?



