nsnotification

iOS - communication between API object and controllers

落花浮王杯 提交于 2019-12-04 15:38:40
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 was about 10-15 different methods that the API responded to (send via http POST, result in JSON). Of

UIProgressView progress update very slow within AlamoFire (async) call

↘锁芯ラ 提交于 2019-12-04 15:11:04
Inside an AlamoFire get request I'm trying to update my progress bar. Like so: alamofireManager.request(.GET, urlPath, parameters: params).responseJSON{(request,response,JSON,error) in ...<code here>... dispatch_async(dispatch_get_main_queue(), { NSNotificationCenter.defaultCenter().postNotificationName(LoginVCHideSpinnerAndShowProgressBarName as String, object: self) }) ...<more code here>... } For some reasons this takes a few seconds to execute and if I use dispatch_sync instead the app just seems to get stuck at that point but the UI doesn't freeze up (the activity indicator spinner keeps

NSNotification troubles

[亡魂溺海] 提交于 2019-12-04 03:54:46
问题 When my class initializes, it adds itself as an observer for a bunch of different Wi-Fi notifications. For some reason, the selector isn't running when any of these things happen. Any ideas? Thank you ahead of time. -(id) init { if (self) { sself = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWModeDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name

removeObserver with NSNotification… what am I doing wrong?

五迷三道 提交于 2019-12-03 18:59:31
问题 Basically, I have a view1 which at some point, calls view2 (via presentModalViewController:animated: ). When a certain UIButton in view2 is pressed, view2 is calls a notification method in view1 and immediately afterward is dismissed. The notification method pops up an alert. The notification method works fine and is called appropriately. The problem is, every time view1 is created (only one view1 should exist at a time), I presumably get another NSNotification being created because if I go

UIKeyboardDidShowNotification called multiple times, and sometimes with incorrect keyboard dimensions

爱⌒轻易说出口 提交于 2019-12-03 16:14:12
问题 I am trying to move a UITextView above the keyboard whenever the keyboard appears/changes. Let's say I have the English keyboard displaying and then switch directly to the Chinese keyboard (which is taller than the standard English keyboard). In this scenario my text view always appears too high (to the naked eye, it looks like the text view is incorrectly offset by the size of the Chinese keyboard "input accessory view". I'd post an image but lack the reputation to do so :) ). I am adjusting

UIKeyboardDidShowNotification called multiple times, and sometimes with incorrect keyboard dimensions

可紊 提交于 2019-12-03 06:18:43
I am trying to move a UITextView above the keyboard whenever the keyboard appears/changes. Let's say I have the English keyboard displaying and then switch directly to the Chinese keyboard (which is taller than the standard English keyboard). In this scenario my text view always appears too high (to the naked eye, it looks like the text view is incorrectly offset by the size of the Chinese keyboard "input accessory view". I'd post an image but lack the reputation to do so :) ). I am adjusting my text view position when my app receives a UIKeyboardDidShowNotification (using

NSNotification troubles

冷暖自知 提交于 2019-12-01 18:39:21
When my class initializes, it adds itself as an observer for a bunch of different Wi-Fi notifications. For some reason, the selector isn't running when any of these things happen. Any ideas? Thank you ahead of time. -(id) init { if (self) { sself = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWModeDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWSSIDDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector

Giving notification to another class with NSNotificationCenter

拟墨画扇 提交于 2019-12-01 07:09:17
问题 So my goal is to deliver a notification to another class with using NSNotificationCenter , I also want to pass object with the notification to the other class , how should I do this? 回答1: You must first register a notification name [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startLocating:) name:@"ForceUpdateLocation" object:nil]; // don't forget the ":" And then post a notification with a dictionary of parameters [[NSNotificationCenter defaultCenter]

NSNotificationCenter selector not being called

て烟熏妆下的殇ゞ 提交于 2019-12-01 02:50:44
问题 In my iPad app, in one class I register for a notification: NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(selectedList:) name:@"TTSelectedList" object:nil]; My selectedList: method looks like this: - (void)selectedList:(NSNotification*)notification { NSLog(@"received notification"); } Then in another class (a UITableViewController ) I post that notification when a row is selected: - (void)tableView:(UITableView *)tableView

How do I check if an UIViewController is currently being displayed?

房东的猫 提交于 2019-11-30 17:46:29
How do I check if an UIViewController is currently being displayed? My UIViewControllers are listening for NSNotifications - even if when they are not displayed (ie not shown). So I could have 10 UIViewController in the background observing NSNotifications from NSNotificationCenter . When an NSNotification is posted and received by the UIViewController , I'd like to find out if it is currently being shown. If it is not, I will just set a boolean so that it will processed when the View is presented. If it currently being display, I will do more things like update tables immediately, and so