nsnotification

iOS - communication between API object and controllers

点点圈 提交于 2020-02-01 08:18:07
问题 I am curious about 2 things: 1 whats the efficient and easy-to-scale way to design communication between object that communicates with API and viewcontrollers 2 how to design the communicating object itself (how to design methods to be scalable,..) (My approach mention below is messy, I know, but the deadlines were crazy and until now I didn't have time to think about it really.) Let me introduce the task I was dealing with: I had to write 2-3 apps depending on communication with API. There

Objective-C 接口编程

筅森魡賤 提交于 2020-01-07 04:27:17
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. @Protocal (协议) @protocal 是Objective-C 中普遍存在的接口定义方式,即在一个类中通过@protocal 中定义接口,在另外的类中实现该接口,这种定义方式夜晨为"delegate"模式。@protocal 声明了可以被其他任何类实现的方法,协议仅仅是定义一个接口,由其他类区负责实现。 "delegate"模式的使用共分为三个步骤: 1)接口声明:创建 一个protocal 文件T estDelegate @protocal TestDelegate<NSObject> @required -(void)doSomething; @end 2)接口回调: 定义一个类A,包含一个遵从此协议的属性CC,并定义一个方法用调用CC的方法,这样当实例化A的对象时,就可以通过delegate回调了。 @interface TestAppDelegate:NSObject { id <TestDelegate> delegate; } @property (retain) id delegate; @end @implementation TestAppDelegate -(void)doSomethingWithProtocal { [self.delegate doSomething]

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

iOS - NSNotificationCenter multiple UIKeyboard notification

北城余情 提交于 2020-01-02 13:50:15
问题 I have two view controllers let's call them A and B (1) in A I show a popOver containing a textField (2) in B there is an UITextView used for simple text editing I Have to manage the keyboard in A and in B to scroll the content hidden by the keyboard. I know how to reposition the content. What I need is a way to have different behavior on the same notifications types that in my are UIKeyboardWill(Show/Hide)Notification. What I've done so far : (1) I've added this code in each controller [

Class method and instance method with the same name in Objective-C

妖精的绣舞 提交于 2020-01-02 02:35:17
问题 I have a solution for a notification problem which works well, but I'm afraid might be a bad idea. I have a notification that needs to be handled by each instance of a class and by the class itself. To handle this, I'm registering for a notification by both the class and instances of the class. Because it's the exact same notification, I've named the class and instance method the same. This follows the standard we've set for how notification handlers are named. Is this a bad idea? Is there

ALAssetLibrary Notification and enumerateAssetsUsingBlock

若如初见. 提交于 2019-12-23 05:37:22
问题 I'm building an iOS app that allows a user to take a picture and save it to a custom album, which populates a UICollectionView in the app with the photos from the album. I found plenty of examples on the web on how to do this, but I could NOT get past a stubborn problem with the most recent picture not showing up in the album. I ended building a work around using notifications and a serial dispatch queue, but I think it can be improved. Here's how I'm saving the pictures and then repopulating

iOS - NSNotificationCenter memory leak

不羁岁月 提交于 2019-12-22 18:02:31
问题 Instruments reports this a memory leak (98.6%, whatever that means): [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSomeNotification object:self]; "self" is a subclass of UIImageView. Is including "self" in the notification causing a memory leak? If so, how do you resolve it? 回答1: Better check your notification observer. The cause of memory leak might be there. 回答2: Memory leaks are almost always it is not safe. Check again are there leakage accurately!? You can do

How to migrate NSWorkspace notifications to Swift 4?

佐手、 提交于 2019-12-22 15:25:53
问题 In Swift 3 I registered for sleep and wake notifications with this code: let notificationCenter = NSWorkspace.shared.notificationCenter notificationCenter.addObserver(self, selector: #selector(AppDelegate.sleepListener), name: NSNotification.Name.NSWorkspaceWillSleep, object: nil) notificationCenter.addObserver(self, selector: #selector(AppDelegate.wakeUpListener), name: NSNotification.Name.NSWorkspaceDidWake, object: nil) but after migrating to Swift 4, I get this error after applying the

KVO - How to get a list of an objects registered observers

心已入冬 提交于 2019-12-22 04:34:14
问题 I am registering an observer on a bunch of tableview controllers dynamically so I need to remove previous observers if they were registered on the same object. To do this I need to check if the observer exists on the object. Is this possible? I know with NSNotification you can use the NSNotification center singleton but is this the same for KVO? 回答1: No, there is no simple way that I'm aware of. KVO and NSNotification differs in that matter. Why don't you implement your solution with

Add 'addObserver' (NSNotificationCenter ) in a 1st view controller, handle in 2nd [duplicate]

女生的网名这么多〃 提交于 2019-12-19 06:19:14
问题 This question already has answers here : Send and receive messages through NSNotificationCenter in Objective-C? (6 answers) Closed 6 years ago . I saw a few examples about adding observer and handle in the same class, but what I want to know is if it's possible to add observer in first view controller and handle it in second view controller? I want constantly send distance from first view controller and handle it in the 2nd one. The 2nd view controller added as a sub view: addSubview ,