I have two controller in my screen and want to reload one method when push notification receive.
Now question is that listener successfully call when visible specific controller via NSNotificationCenter. But when i am on another controller then listener method not call.
Can i handle it via NSNotificationCenter? If no then what is the best approach for this? Thanks.
Related
I need to model following in RAC.
I have a tabBarController which will subscribe to a notification signal. Say push notification. Also say currently active view controller may also be want to subscribe to the same signal. But if any view controller subscribed to it tabBarController doesn't want to handle it. Otherwise it will handle it. Also when current visible view controller changes. It needs to delegate back the responsibility to tabController.
Currently without RAC I maintain array of observers at tabController. If any observer present for particular kind of notification. It will delegate to viewController otherwise tabController will take care of it.
Any better way to model this using RAC?
I wonder if dealloc is always called when you close a ViewController in Objective-C for iOS. I've done some tests and it seems like it. Except I don't get any logs when I swipe close the application. I figured that maybe XCode doesn't log things if you fully close the app like that.
The reason I wonder this is because I'm sending analytic data when one of the ViewControllers closes and I kinda need to know if dealloc is always called or if there's any better way doing this.
If you want to get notified when app is killed via Swiping , you can use applicationWillTerminate method and in this method , you can check for current view controller in navigation stack and send analytical data for that View controller .
It's not defined when dealloc will be called for a view controller (or pretty much any class), therefore don't use it for sending analytics.
Use viewDidDisappear instead, which you can rely on to be called when the view controller has been removed.
I have 2 UI views both with controllers attached to a tab controller.
ViewA - Used for authentication (contains login textfields and submit button)
ViewB - Used to display profile.
I have set ViewB to be disabled using the utility manager in storyboard, this is to prevent users clicking on the tab before logging in. Once authenticated in ViewA i want to notify ViewB to enable itself and display the profile.
From googling it appears that using NSNotificationcenter is the best way to do this, I have created a simple postNotifiaction that works fine - but I am unsure where to add the receiver in ViewB, I can not add it in ViewDidLoad because it does not load, and is disabled to start with?
Is notification center the best way to do this?
Also, how do i sent a notification to a view that is disabled?
Thanks
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html
Apple documentation link above pretty clearly states that NSNotificationCenter does not retain it's observers, thats why you can't release the dataAnalyzer there - it would be dealloc'd and the notification would attempt to post to a nil reference.
Subscribe to the notification(s) in the -init method of each view controller. That ensures the controller has been created and initialized, and makes each controller responsible for it's own actions.
I'm not entirely sure what your question is, could you rephrase it if the above didn't resolve your problem.
Also, be aware NSNotificationCenter will post to all observers, but it is not async - it waits for each one to finish processing the notification before sending to the next object.
Surely, you have a controller (AppDelegate if anything) that controls the disabled state of ViewB? You could listen for the notification from this controller instance and enable ViewB from it once it receives the notification.
If you must subscribe to the notification from ViewB, then register for it in its (ViewB's) init method (don't forget to unsubscribe from the notification in the dealloc method). This should work because even though the button used to get to ViewB is disabled, the ViewB instance would be instantiated with the launch of your app (or so I assume...).
If you don't instantiate ViewB until the button is tapped, then you must have the controller that enables/disables the ViewB button be in charge of listening for the notification and enabling the button to access ViewB.
I think this logic is a little ambiguous. This is what I've understood about your application:
-> Tab Bar Controller
---> Controller 1 - Login
---> Controller 2 - Profile (disable as default)
You have not to insert you notify into Controller 2 but in TabBar because it "controls" the other controllers (sorry for the word joke). I think the best solution can bes this:
TabBar
Observer of a notification about "user changed" and check it: if user is logged then enable profile controller, if user is anonymous then disable it.
Controller 1 - Login
When the user is logged in / logged out fire a notification of "user changed".
That's all, your controller 2 can live without know user state. Let me know if you have problem coding this logic.
Why you not just call [viewB enableItselfSomehow]; in -someAuthenticationSucceedFeedback method?
Registering notifications for just enabling/disabling view is a bad tone as for me
Did you disable the view or the tab button?
If you disable the tab button, you could enable it and switch to the profile tab by doing
self.tabBarController.selectedViewController = profileViewController;
You can place this code in ViewA's view controller. To get the profileViewController, you can use this code instead
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1]
Assuming that your profile is at index 1
Hi I have a viewcontroller in a tabview controller. I decided to use NSNotification to flag when views in the tabview controller need to update their data. Previously each had logic to tred to decided the state of the data model and update accordingly.
My update code calls some stuff that in turn call delegate methods. These were all working when not using notification.
My first attempt at notifying seemed to call the selector before the view controller had initialised (before viewDidload at least). Among other thing the delegate methods were never called when the update in the notification selector was run and the view controller didn't get updated. Seems like the viewcontroller is in some unknown state.
I ran a test and put the same update code in the viewDidLoad and only called the notification code after the viewDidLoad had been called. This works.
My question is ,is there another way of preventing the notification selector method being called before viewDidLoad or the object is otherwise correctly initialised.
I am using storyboard so I am not programming the creation of views etc.
I hope this is clear - posting a whole bunch of code would not had been any easier.
Thanks guys, both right! I set up the Notification in app delegate. I should put it at the end of viewDidLoad. Then it is only called when there is a subsequent update and I don't need a flag to stop the first notification from doing an update before the object is up and running.
I currently have my app setup to receive push notifications. When I am in the app and I receive a push notification, I have a custom UIView slide down from the top of the screen and displays the notification (similar to the new version of Whatsapps). Essentially I am trying to mimic the banner style notifications in iOS 5.
What I am looking to do now is have that UIView clickable. When clicked, based off of the type of notification received, will bring me to a different view controller (similar to how whatsapp does it).
For example, I am in chatroom A. I receive a message in chatroom B. The slider view comes down, I tap that and it brings me to chatroom B. In the push notification I am essentially passing the chatroomID which I can use to identify which room (essentially some view) I would like to join.
I have a root view controller setup already with a navigation controller as well. I am modally pushing other view controllers as the user navigates throughout the app. Would I dismiss the current view and push the next view when receiving a notification?
Also how would I go about making my slider view detect taps like the iOS banner notification? (and maybe have a selected animation, similar to the "grey clicked style" in a UITableView)?
Here's a trick for detecting a tap on a view: Use a UIControl instead of a UIView (UIControl is a superclass of UIView). Then use the UIControl's addTarget:action:forControlEvents: method with controlEvents of UIControlEventTouchUpInside to send the object of your choice a message when the view is tapped. If you're configuring the view in Xcode's graphical editor, you can use the Identity inspector's Class field to change the class of your view from UIView to UIControl, and then you can configure the Touch Up Inside event.
(I learned this technique from iOS Programming: The Big Nerd Ranch Guide by Conway and Hillegass.)
You could very easily present a clear button over the view with an "if" statement that matches your criteria and perform a view animation from there with the transition back to the other view.