jjzjj

nsnotification

全部标签

ios - 不调用 NSNotification keyBoardWillShow 和 keyboardWillHide

我有一个带有自定义View的xib文件,上面有很多文本字段subview。我已经将每个文本字段的委托(delegate)设置为文件所有者,并且能够成功地使用texfield委托(delegate)方法。但不幸的是,键盘通知方法keyboardWillShow:和keyboardWillHide:根本没有被调用。我在textfieldShouldBeginEditing添加了观察者,并在textFieldDidEndEditing移除了观察者。这是我的代码片段:添加观察者-(void)textFieldShouldBeginEditing:(UITextField*)textField{

objective-c - NSNotification 在父类(super class)中观察并在父类(super class)和子类中处理

我有类ParentClass观察NSNotification。ParentClass处理通知。ChildClass继承了ParentClass,也负责处理通知。发送通知的顺序是确定的吗?换句话说,ParentClass是否总是在ChildClass之前处理通知,反之亦然? 最佳答案 这取决于实例化哪些类以及如何实例化,形成实际对象。还要看子类是否调用super进行处理。否则,正如NSNotificationCenter的文档所说,接收通知的对象的顺序是随机的,并且不取决于您是子类还是父类(superclass)。请考虑以下示例以便更

ios - NSNotification Center 只能在第二次工作? TabbarController 到 NavigationController

场景我有两个ViewController:Tabcontroller和Viewcontroller。在第一个中,我定义了我的发布通知,在第二个中,我添加了一个带有接收方法的观察者。在我的标签Controller(发件人)上:-(void)tabBar:(UITabBar*)tabBardidSelectItem:(UITabBarItem*)item{[[NSNotificationCenterdefaultCenter]postNotificationName:@"RestartBtn"object:selfuserInfo:@{@"isHidden":@"YES"}];}在View

ios - 圆弧 : Dealloc not being called

我不明白为什么我需要在某些block中有一个弱的self,而其他的似乎工作正常。如果我在Notificationblock中没有对self的弱引用,dealloc将不会被释放。不过,它与第二个效果很好。//Whenusingthis,deallocisNOTbeingcalled[[NSNotificationCenterdefaultCenter]addObserverForName:PROD_DONEobject:nilqueue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*note){[selfhideAds];}

iphone - "unrecognized selector sent to instance"键盘出现时

当我在我的应用程序屏幕中单击一个文本字段并且键盘出现时,xcode调试器显示此错误:[mainViewControllerkeyboardWasShown]:unrecognizedselectorsenttoinstance0x5867ac0在mainViewController的viewDidLoad方法中,我这样调用registerForKeyboardNotifications方法:[自行注册键盘通知];这是它的实现(在mainViewController.m中):-(void)registerForKeyboardNotifications{[[NSNotificationC

ios - UIView 中的 NSNotifications 和 removeObserver

我创建了一个子类UIView:BeneficialsFormView*view=[[BeneficialsFormViewalloc]init];view.alpha=0;view.delegate=self;view.screenView=[self.delegatedisplayEntityForm:view];委托(delegate)调用是为了显示UIView并返回一个我用来禁用背景触摸的UIView(只是一个具有黑色背景颜色和降低的alpha的UIView)。在子类UIView中,我添加了键盘通知:-(void)awakeFromNib{DLog(@"fired");[[NSN

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

我正在尝试运行以下代码,除非发送了NSNotification。我不知道如何将NSNotification放在if语句中:if(!self.subViewControllerProv){self.subViewControllerProv=[[ProvViewControlleralloc]init];}[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(handleNotification:)name:@"SomeNotification"object:nil];回顾一下:如果观察到NSNoti

objective-c - NSNotification : does the object property have to be self?

到目前为止,我一直在使用NSNotificationCenter和方法postNotification:aStringobject:anyObjectOfInterestForTheReceiver。但最近我在文档中读到,object字段应该只传递给self。是否有任何我不知道的可怕副作用应该说服我将来只传递self,或者传递任何对象都可以吗?谢谢! 最佳答案 您可以将任何对象作为通知的object传递,但约定是object是“正在执行通知的事物”(并且您将userInfo字典中的其他相关状态)。它主要是self的原因是因为通常执行

ios - 发送 NSNotification 时无法识别的选择器

我正在尝试在iOS应用程序中实现可折叠的表格View。为此,我在部分标题中设置了一个手势识别器,它将向父Controller触发NSNotification,然后刷新显示展开View的View。一切正常,直到父Controller收到它的消息,这将导致发生以下错误:'+[MasterViewControllerreceiveTestNotification:]:unrecognizedselectorsenttoclass0xa92a8'我浏览了这个网站并发现了一些与此错误相关的帖子,但据我所知我没有犯这些错误。我的注册发生在Controller的初始化过程中,看起来像这样:[[NSN

ios - 是否有电话状态的NSNotification

当设备打开/关闭电话时,我们是否可以观察到NSNotification? 最佳答案 NotificationCenter不会发送任何关于此的通知,但请看一下iOS4中引入的CTCallCenter类。它有一个callEventHandler属性,您可以将代码块分配给该属性,并使用调用状态信息进行调用。只有当您的应用程序处于前台时(或当有来电时从前台退出),处理程序才会被调用,但它会告诉您用户是否正在拨号(CTCallStateDialing)、接听电话(CTCallStateIncoming)、接听/连接(CTCallStateCo