gpt4 book ai didi

ios - 如何在 if 语句中检查 NSNotification

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:21 35 4
gpt4 key购买 nike

我正在尝试运行以下代码,除非发送了 NSNotification。我不知道如何将 NSNotification 放在 if 语句中:

if (!self.subViewControllerProv) {
self.subViewControllerProv = [[ProvViewController alloc] init];
}


[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:) name:@"SomeNotification" object:nil];

回顾一下:如果观察到 NSNotification 消息,则 allocinit ProvViewController 如果没有,则不要't.

最佳答案

那么做这样的事情怎么样:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification) name:@"SomeNotification" object:nil];

然后

-(void) handleNotification {
//BOOL _hasBeenSent in your interface
_hasBeenSent = YES;
}

然后在你的代码中

if(_hasBeenSent) {
NSLog(@"The notification has been sent!");
}

关于ios - 如何在 if 语句中检查 NSNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15293261/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com