nsnotificationcenter

NSNotificationCenter : list of observers?

主宰稳场 提交于 2020-01-09 10:35:51
问题 Is it possible to get the list of observers (objects and selectors) for a given notification name? (NSNotificationCenter) 回答1: (iOS 9, Swift 3) If you want to find out which observers are currently registered in NotificationCenter , break and print its debug description: (lldb) e print(NotificationCenter.default.debugDescription) Each line of the output will contain (Notification) Name , Object , Observer , Options . Multiple calls to NotificationCenter.default.addObserver with some

细说KVO和Notification

余生颓废 提交于 2020-01-07 10:34:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 做iOS开发已经不短时间了,忙于项目,遇见问题,就去Google,忘记了积累,最近深知其中的危害,深深体会到 经验不在于年限而在于积累 这个道理。 从遇见的问题说起,想实现时刻监控UITextField有无文本这样一个功能,听起来很简单,感觉做起来也很容易,但就是这么个简单的问题,让我花费了很长时间,很是懊恼,决定重新审视下自己,整理下这方面的知识,来提高自己!好了废话少说,进入正题! 实现功能 监控 UITextField是否有输入文本 从而实现按钮是否可以点击 解决方案 Notification 代码实现 //文本框 UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 280, 50)]; textField.tag = 888; [textField setClearButtonMode:UITextFieldViewModeWhileEditing]; [textField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; textField.layer.borderWidth = 0.5f; /

iOS NSNotificationCenter 使用姿势详解

人盡茶涼 提交于 2020-01-07 06:05:18
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 最近在做平板的过程中,发现了一些很不规范的代码。偶然修复支付bug的时候,看到其他项目代码,使用通知的地方没有移除,我以为我这个模块的支付闪退是因为他通知没有移除的缘故。而在debug和看了具体的代码的时候才发现和这里没有关系。在我印象中,曾经因为没有移除通知而遇到闪退的问题。所以让我很意外,于是写了个demo研究了下,同时来讲下NSNotificationCenter使用的正确姿势。 NSNotificationCenter 对于这个没必要多说,就是一个消息通知机制,类似广播。观察者只需要向消息中心注册感兴趣的东西,当有地方发出这个消息的时候,通知中心会发送给注册这个消息的对象。这样也起到了多个对象之间解耦的作用。苹果给我们封装了这个NSNotificationCenter,让我们可以很方便的进行通知的注册和移除。然而,有些人的姿势还是有点小问题的,下面就看看正确的姿势吧! 正确姿势之remove 只要往NSNotificationCenter注册了,就必须有remove的存在,这点是大家共识的。但是大家在使用的时候发现,在UIViewController 中addObserver后没有移除,好像也没有挂!我想很多人可能和我有一样的疑问,是不是因为使用了ARC?在你对象销毁的时候自动置为nil了呢

Multi select is not working properly in IOS

旧时模样 提交于 2020-01-07 00:52:08
问题 I have a problem with setting the checkmark for a row in iOS table view If I select one element above, the next 13th element is also getting selected, I not sure why? Should I have to do something with the table before setting the checkmark, cause I am just checking one condition and if that condition is true I am setting the accessoryType as checkmark, below is the code. Note:- When this happen the 13th row will not get selected, it just changes the accessory type of that row. if let cell =

NotificationCenter is not getting trigger in my obj c class ( utills class or object class ). Not an viewcontroller

試著忘記壹切 提交于 2020-01-06 08:43:12
问题 I have one obj c class, swift file. And here is my code : #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "InterfaceManagerInstance.h" void IOSInterfaceManager::testMethod() {} void IOSInterfaceManager::initialize(){ } std::string IOSInterfaceManager::getColorPrimary(){ return ""; } void IOSInterfaceManager::onOver(int nameID,int fameid, int nickNameID){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter

Is there a way to access the notifications shown in the notification center?

不羁岁月 提交于 2020-01-06 08:10:20
问题 I have kind of to-do local notifications that are fired OK. So for example if 2 notifications have fired the badge number goes to 2. Now I like to handle these notifictaions also when the user just starts the app directly - not via the notifictaion center. So the badge number would be 2, the user clicks on the app icon to start the app and the app should know which 2 notifications are in the notifictaion center. While I know how to get all scheduled notifications BEFORE they fire - is there a

Not getting screenLock notification on Swift 4 on mac

不问归期 提交于 2020-01-06 06:30:19
问题 For some reason I'm not getting the ScreenIsLocked and ScreenIsUnlocked notifications. I defined that the screen get locked 0 seconds after the screen saver starts and yet no log: import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @objc func screenLocked() { NSLog("yes") } func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application NotificationCenter.default.addObserver( self, selector: #selector

Should I prefer NSNotificactionCenter or .NET events when using Monotouch?

老子叫甜甜 提交于 2020-01-05 12:34:24
问题 When developing in Monotouch, is it "better" to us real .NET event s or NSNotificationCenter ? Simple example: I have a UIViewController . It offers an event " CallbackWhenDisappeared ". This event is triggred in ViewDidDisappear . Who ever is interested can register to the event. I could as well post a " MyFancyControllerHasDisappeared " on the NSNotificationCenter and let interested objects subscribe there. Which version is to be preferred? The disadvantage with the .NET events I see: the

Remove notification observer from another view controller

一曲冷凌霜 提交于 2020-01-05 10:36:43
问题 Hi I am developing Iphone application in which am registering one notification observer for UIApplicationWillEnterForegroundNotification. Now I want to remove that one from another view controller. My code looks like [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationWillEnterForegroundNotification object:nil]; And I am creating one method for removing observer: -(void) removeObserver { [[NSNotificationCenter defaultCenter]

Remove notification observer from another view controller

帅比萌擦擦* 提交于 2020-01-05 10:34:56
问题 Hi I am developing Iphone application in which am registering one notification observer for UIApplicationWillEnterForegroundNotification. Now I want to remove that one from another view controller. My code looks like [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationWillEnterForegroundNotification object:nil]; And I am creating one method for removing observer: -(void) removeObserver { [[NSNotificationCenter defaultCenter]