How to set tab badge from app delegate - objective-c

I'm trying to set the tab badge number on launch when I receive a push or local notification. Accordingly, I'm trying to set this badge number from the Application Delegate. I can set the badge locally from the tab's view controller with self.tabBarItem.badgeValue, and I can set up a method to set it which I can call from the delegate, but there must be a better solution.
Any ideas?

I don't see any problem with this. It's called the AppDelegate for a reason, so that it can act as the main controller for other controllers.

Related

NSNotification or Delegate to register for when the visible view changes

I'm developing a project in objective-c for ios, and I have a view with multiple tabs using a subclass of UITabBarController. Each tab has it's own UINavigationController. When a view loads on a tab, the appropriate activation events fire (viewWillAppear, viewDidLoad, etc.). However, once you tap on a different tab, and tap back, not all these events will fire again since the view is already the visible view for that specific tab (viewDidLoad for example).
My question is this: is there a notification or delegate that I can simply register for and get notified when the visible view in the window changes? I've done some research and I didn't find anything specific for this. What I plan on doing is:
Check the visible view when the tab bar index changes: tabBarController:didSelectViewController
Register for this event on each navigation controller: navigationController:didShowViewController:animated:
By doing this, I should be notified whenever the visibleViewController changes by either changing the tab, or navigating within the tab's navigation flow (except for modals, in this case, I don't care about them. They are handled already).
Is this the right approach?
Have you looked at UITabBarControllerDelegate? This method sounds what you are looking for:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
From the documentation:
In iOS v3.0 and later, the tab bar controller calls this method regardless
of whether the selected view controller changed. In addition, it is called only
in response to user taps in the tab bar and is not called when your code
changes the tab bar contents programmatically.
Here's the link: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
Hope that helps!
First implement the UITabBarController delegate method "tabBarController:didSelectViewController" and register for it in the app delegate. You can't register for it in each navigation controller. Only one object can be the delegate. In that method, typecast it to a UINavigationController.
Then get the UIViewController by calling "topViewController" on that UINavigationController. Then call the viewWillAppear: method directly on it.

How to perfom an action when Tab in a CustomTabBar is pressed?

I have a CustomTabBar created working as expected. Apart from selecting tabs, I want to perform an action (refresh some info) on one of my viewcontrollers when this tab is already selected. I mean, I have a tab selected and I press that tab again and fire an action of the ViewController.
Any suggestion?
If your custom tab bar controller is a subclass of UITabBarController then you can provide a delegate that responds to tabBarController:didSelectViewController:. In iOS 3.0 or later this will still fire if the view controller is the same as the one already selected, so you can track this and send your update messages to the correct view controller in this case.
If you don't subclass UITabBarController and have written the tab bar changing code yourself, then implementing a delegate protocol and sending notifications of tab changes and other events is probably a good idea.

Setting an identifier for an Xcode Storyboard Segue in a UITabBarController, and getting a pointer to its view controller

This is my first app using storyboards/segues, and I'm pretty sure the answer to this is easy, but I'll be as thorough as possible in describing my issue.
I am making a simple app which has a Tab Bar Controller scene and two View Controllers.
My app launches by being sent a URL from another app. The application:openURL:sourceApplication:annotation: method in the app delegate performs some work to determine
which tab to display first, and
what information to display on it.
My goal is to use the performSegueWithIdentifier method (I'm open to alternatives though) from within the AppDelegate to select the tab, and also find a way to send a method to the instance of the view controller created by the storyboard.
Issue #1 is that I can't set an identifier. When I select the tab "relationship" there are no choices available in the Attributes Inspector (it says "Not Applicable"). How do I set a name for this segue? Can I? Or is there some rule under which UITabBarController segues can't be trigger programmatically?
Issue #2 is that I can't find a way to have a pointer to the view controller. Pre-Storyboard I would alloc and init a new view controller and then set it up, but here if I do that, it does not get displayed when my app launches (I think this is because Storyboard is displaying a different instance of the same view controller.)
I know this post is long, but I feel like I'm missing something simple. What is it?
Sounds like you need to have your AppDelegate set the entry point to your storybard.

Opening specific view from push notification

I have set up push notifications successfully on my app but I want the user to go to a certain view when the swipe the notification (iOS 5) opposed to just starting the app up.
The view controller is called statsViewController
Does anyone know how to do this? Thanks in advance
You can add a custom dictionary to your push notification payload. See Apple's push notification guide. When you receive the notification, grab the payload and load the view controller based on what's inside.

Is there a way to change Views in iOS without using UINavigationController?

I have a login page at the beginning of my app that I do not want on the view stack. Is there a way to load my first post-login view after the login without using UINavigatorController?
Is there a better way to be doing this? Should I be using 2 UINavigationControllers? Is there a way to change the RootViewController for a UINavigationController?
Yes, you can change root controller of window. Set window's property rootViewController to new controller and you're done. Don't forget though that first controller (one you are removing) will not receive viewWillDisappear: and viewDidDisappear: messages. Send them yourself before switching controllers if you're interested in them.
You might also look at UIViewController#presentViewController