Send and receive messages through NSNotificationCenter in Objective-C?

后端 未结 6 1488
感动是毒
感动是毒 2020-11-21 22:40

I am attempting to send and receive messages through NSNotificationCenter in Objective-C. However, I haven\'t been able to find any examples on how to do this.

6条回答
  •  名媛妹妹
    2020-11-21 22:54

    if you're using NSNotificationCenter for updating your view, don't forget to send it from the main thread by calling dispatch_async:

    dispatch_async(dispatch_get_main_queue(),^{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"my_notification" object:nil];
    });
    

提交回复
热议问题