Tag: nsnotifications

为什么我得到这个代码的“wait_fences:未能收到答复”?

为什么我得到这个代码的“wait_fences:未能收到答复”? 这是我使用通知回传给主线程的方式吗? #import "ViewController.h" @implementation ViewController @synthesize alert; #pragma mark – Background Thread Test Methods – (void) ConfigTasksForBackground:(id)sender{ NSLog(@"ConfigTasksForBackground – Starting"); [NSThread sleepForTimeInterval:6]; [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object:self]; NSLog(@"ConfigTasksForBackground – Ending"); } #pragma mark – Callbacks – (void) ModelChangedHandler:(NSNotification *) notification { if ([[notification name] isEqualToString:@"ModelChanged"]) { NSLog(@"ModelChangedHandler"); [self.alert dismissWithClickedButtonIndex:0 animated:false]; } } #pragma mark – […]

视图上的事件显示更改(Youtube MPMoviePlayerViewController)

我想知道什么时候YouTube MPMoviePlayerViewController出现(以编程方式)后,点击了允许在iOS中播放video的UIWebView,以获得和控制这个视图。 因为我想从播放器获取信息,如当前的播放时间,加载时间…就像在一个普通的MPMoviePlayerViewController中。 谢谢

我可以观看另一个class的NSNotification吗?

我试图让我的头在NSNotificationCenter。 如果我在我的App Delegate中有这样的东西: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(something:) name:@"something" object:nil]; —– -(void)something:(NSNotification *) notification { // do something } 我可以以某种方式在另一个视图控制器中看这个吗 在我的情况下,我想用一个表格在视图控制器中观看它,然后在收到通知时重新加载表格。 这可能吗?

是否有一个NSNotification电话状态

我们可以观察设备开机/关机时的NSNotification吗?

keyboardWillShow调用两次

我有一个键盘通知,如keyboardWillShow和keyboardWillHide的视图 所有的代码处理与我使用的通知是从苹果的示例代码“KeyboardAccessory” 当我第一次进入这个视图时,一切正常。 但是当我从子视图中回到这个视图时,每次我点击一个button说: [myTextField becomeFirstResponder]; keyboardWillShow和keyboardWillHide方法将每次调用两次。 这真是令人困惑, 任何人都可以帮助我吗? 万分感激!

删除iOS 5 ARC中的NSNotificationCenter观察者

我有一个iOS 5基于ARC的项目,并且在我应该删除在UIViewController注册的NSNotificationCenter观察值的观察者方面遇到困难。 SO上的类似post曾经说过这应该在-dealloc方法中完成。 尽pipe这个方法在ARC项目中不是必需的,但我已经用下面的代码添加了它: – (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } 作为一个testing,我打开UIViewController (在UINavigationController ),做一些触发通知的事情,然后点击Backbutton将其popup堆栈。 然后,我重新打开UIViewController ,并做了更多的事情来触发通知,但注意到每个callback都被调用了两次 – 这表明以前的通知还没有被注销。 重复此过程只会导致每个callback被调用的次数超过了,所以它们似乎永远不会被注销。 任何帮助,将不胜感激!

为什么我的NSNotification被多次调用观察者?

在一个应用程序中,我使用了几个视图控制器。 在一个视图控制器上,观察者被初始化如下: [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MyNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:@"MyNotification" object:nil]; 即使在初始化myMethod:的执行次数之前删除NSNotification myMethod:正由相应视图控制器上重复视图的myMethod:加起来。 为什么会发生这种情况,我该如何避免myMethod:多被调用一次。 注:我确定通过使用断点,我没有多次调用postNotification出错。 编辑:这是我的postNotification看起来像 NSArray * objects = [NSArray arrayWithObjects:[NSNumber numberWithInt:number],someText, nil]; NSArray * keys = [NSArray arrayWithObjects:@"Number",@"Text", nil]; NSDictionary * userInfo = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:self userInfo:userInfo]; 编辑:即使移动我的订阅viewwillappear:我得到相同的结果。 myMethod:被多次调用。 (我重新加载viewcontroller的次数)。 -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self […]

是否可以使用通知回到IOS应用程序的主线程? (比较performSelectorOnMainThread)

是否可以使用通知回到IOS应用程序的主线程? (比较performSelectorOnMainThread)。 也就是说,有什么gottcha这个目的? 背景 想要从后台线程callback主UI线程(例如performSelectorInBackground) 可以使用performSelectorOnMainThread进行通信,但想知道是否可以使用通知? 例如 [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object:self];

KVO vs NSNotification vs协议/代表?

虽然我有一些想法用于什么时候,但确切的用法还不清楚。 有人可以用例子来解释吗? 谢谢。

为什么不从NSNotificationCenter删除观察者:addObserverForName:usingBlock被调用

我很困惑,为什么在下面的代码中永远不会删除观察者。 在我看来,我有以下几点: -(void)viewDidAppear:(BOOL)animated{ id gpsObserver = [[NSNotificationCenter defaultCenter] addObserverForName:FI_NOTES[kNotificationsGPSUpdated] object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note){ NSLog(@"run once, and only once!"); [[NSNotificationCenter defaultCenter] removeObserver:gpsObserver]; }]; } 观察者永远不会被移除,并且每次发送通知时都会输出语句。 任何人可以提供任何指导?