NSNotification is being called multiple times from UITabBarController

前端 未结 2 872
北恋
北恋 2021-01-07 06:31

I have a UITabBarController, which has 4 tabs. Each one of those tabs is a separate UIViewController. I have objects on each one of those 4 VC\'s t

2条回答
  •  孤独总比滥情好
    2021-01-07 07:03

    it should be called only once so that it never gets called again

    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodName:) name:@"name" object:nil];
    });
    

提交回复
热议问题