I am adding UITabBarController to the window, and setting the viewControllers property of the UITabBarController to the array of ViewControllers.
If i am setting the badge value inside the viewController then its working fine.
self.tabBarItem.badgeValue = #"3";
But if i am setting the viewControllers property of the UITabBarController to the array of navigation controllers which is having view controller as the rootviewcontroller, then its not setting the badge value.
Any suggestions ??
Thanks
Yes, i got the answer.
[[self navigationController] tabBarItem].badgeValue = #"3";
Or this:
[[self.tabBarController.tabBar.items objectAtIndex:2] setBadgeValue:[NSString stringWithFormat:#"%d",[UIApplication sharedApplication].applicationIconBadgeNumber]];
Related
I embedded tableviewcontroller into a navigation controller, set the title, but it does not show when I run the app.
What is wrong?
This is the setting of the tableviewcontroller
Here is the setting of the navigation controller
First check, your NavVC must be initial VC.
If not then try this piece of code
-(void) viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
you must be presenting the plain table view instead of navigation controller. What you need to do is make you tableview as root view for a navigation controller and present the navigation controller.
var nav: UINavigationController = UINavigationController(rootViewController: vc)
//then present the nav
Change the initial VC from Navigation Controller to your TableViewController
I did not set the StoryboardId for Navigation controller.
I am trying to use a SWrevealViewController for sidemenu . One of the options on it is "User Profile" . Since I access user's profile from various other views , I would like to have to have a push segue to this VC. However , a push segue is not working from SWRevealViewController to UserProfileVC.
Can anyone suggest how I may use a push sugue from SWRevealVC?
Here's my solution:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil]
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"YOUR_VC_STORYBOARD_ID"];
SWRevealViewControllerSeguePushController *segue = [[SWRevealViewControllerSeguePushController alloc] initWithIdentifier:#"ANY_ID" source:self destination:vc];
[segue perform];
Swift version will be
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginRoot") as! UINavigationController
let segue = SWRevealViewControllerSeguePushController.init(identifier: SWSegueRearIdentifier, source: self, destination: vc)
segue.perform()
Navigation controller is UIViewcontroller. i used navigation controller otherwise use UIViewController object.
Create a custom segue from your Reveal View Controller to your side menu view controller using the storyboard editor. Set the identifier as "sw_rear", kind as "Custom" and class as "SWRevealViewControllerSegueSetController".
With this, if you create ordinary "push" segues from your menu view controller to other view controllers they should be pushed normally.
How to handle situation when I use ARC and add view of UIViewController?
MyViewController *vc = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[someView addSubview:vc.view]; //this retain vc.view
because addSubview retain onlu view, not controller, so controller is released. Before ARC there was a way to retain controller as long as neede, but how to prevent ARC to release View Controller?
I had similar situation solved by declaring vc as property with default strong attribute.
#define AntiARCRetain(...) void *retainedThing = (bridge_retained void *)__VA_ARGS; retainedThing = retainedThing
And then call AntiARCRetain(controller);
Why would you need a new ViewController there?
You should just add your View as Subview and handle everything with the ViewController of "someView"
I've got a problem concerning Navigationcontroller in AppDelegate. I'm using a storyboard, which looks like this:
As a result of using Push notifications, i've got the following function in my AppDelegate File:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
}
When the notification arrives I want to initialize the "Detail View" - Controller which needs an ID as a parameter. This ID is part of my payload so it is present in didReceiveRemoteNotification.
I'd like to to the follwing:
DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:#"detail"];
detail.conversationID = theID;
[self.navigationController pushViewController:detail animated:YES];
My question at this point is: how can I get the navigation controller? I've searched for a function like "getNavigationControllerByIdentifier" or something like this, but found nothing. I can't instantiate the Detail View Controller directly because the navigationbar is missing there.
I hope you understand what I mean - if you think my approach is completly wrong please correct me ;o)
Just another small information: It's not important for me that the back button in the Detail View Controller goes back to the Table View - it's enough when it links to the controller with the button "Load Table View".
Thank you for help!
UINavigationController is a UIViewController subclass and can also be assigned an identifier in the storyboard.
Use -instantiateViewControllerWithIdentifier: to create the UINavigationController and it's root view controller. You may need to instantiate all of the intermediate controllers in code and modify the navigation controller's viewControllers property to set up the appropriate navigation stack. This way when the app launches into the detail view, they can find their way back as if they had manually pushed all the way through via the interface.
You can use rootViewController on your window object.
UIViewController *rootViewController = self.window.rootViewController;
// You now have in rootViewController the view with your "Hello world" label and go button.
// Get the navigation controller of this view controller with:
UINavigationController *navigationController = rootViewController.navigationController;
// You can now use it to push your next view controller:
DetailViewController *detail = [navigationController.storyboard instantiateViewControllerWithIdentifier:#"detail"];
detail.conversationID = theID;
[navigationController pushViewController:detailViewController animated:YES];
I am trying to set the action for a UIBarButtonItem I have in my MainWindow.xib. I keep going round and round and I'm not getting anywhere. My controller hierarchy is as follows:
UITabBarController
UITabBar
UINavigationController
UINavigationBar
UIViewController
UINavigationItem
UIBarButtonItem // THIS
UITabBarItem
How can I set the action to it? I see a "selector" option in IB, but I'm not sure how to set it.
So, based on your comment answer, you'll have to use the targetand action properties.
Target is the object that will receive the action.
Action is a selector (a method), from the target object.
myBarButtonItem.target = self;
myBarButtonItem.action = #selector( myMethod: );
Remember action method must have the following signature:
- ( IBAction )myMethod: ( id )sender;
The sender object will be the object that triggered the action, in your case the UIBarButtonItem.