Can we use the UINavigationController animation on UITabBarController - iphone

I am using UITabBarController so that it can be displayed on all views once declared in delegate, but my requirement is that when any tab bar button clicked it should work like a button works on pushViewController:. Is it possible, can anyone guide here.
Thanks in advance.

you can just create a UINavigationController with toolbar hidden.
Then create a root view controller which has toolbar or custom view on bottom and add buttons on it.
Add targets to that buttons to push view controllers which you want.

This is not a typical behavior, however you can try as follows:
Declare a delegate (UITabBarDelegate) for your UITabBar, and implement the method -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item to get notified of the user selecting tabs. In this method you will push a new view controller in the navigation controller's stack (or pop one that is not desired).
Depending on your needs, you may also need to manually set the currently selected tab bar item. To do so you can manipulate the tab bar's #property(nonatomic) NSUInteger selectedIndex. Be aware that changing this property will trigger another call to tabBar:didSelectItem: which may or may not be wanted.

Related

iPhone Dev - Is it possible to remove a button from a UINavigationController's navigationBar?

When I push a view via my app's navigationController, it automatically puts a back button on the left side of the navigationBar. Is there any way I can just remove this? (I want to put my own buttons on the screen that will allow the view to be popped).
From the comments, you can hide the back button for a viewController by using its navigationItem property. (which is the UINavigationItem corresponding to that viewController in the stack of the navigationController. its how you control what shows up on the bar for specific view controllers (see Apple Doc here)).
To answer your question, set the navigationItem's hidesBackButton property to YES. Something like this probably called in your viewControllers viewDidLoad: or similar method.
myViewController.navigationItem.hidesBackButton = YES;
have you try with self.navigationItem.hidesBackButton=YES;?
If I wanted to do it, I'd hide the Navigation bar on push (non animated hide), add a toolbar, and add any custom stuff I want to the toolbar.
on popping the view controller, make sure to unhide the navigation bar. It'll work

UITabBarController - detect when tab is UNselected

If you have 4 tabs, what is the best way to inform one of the view controllers that it has been "deselected". In other words, that another tab was selected?
I can't just use viewDidDisappear, because that may happen anyway. Is there another way for a view controller to know that it is no longer the active tab?
The TabBar delegate (didSelectViewController) tells me which was selected, but I need to know which tab was active BEFORE the selection, so that I can tell the view controller to kill some things.
There is a TabBar delegate method of shouldSelectViewController which gets called to ask permission to change the view controller and a UITabBarController property of selectedViewController or selectedIndex.
Would need to verify that selectedIndex or selectedViewController does not change until the shouldSelectViewController method returns though...

viewWillAppear: method doesn't seem to respond while using tab bar and navigation controllers together

I am using Tab bar + navigation based application and I have 4 tab bars. When I navigate from one view controller to another view controller, the viewWillAppear: method doesn't seem to respond and I am being forced to call it manually by creating the object of the next view controller. So my question is, how do I avoid calling the viewWillAppear: method manually whenever I navigate from one view controller to another? Instead, it should get triggered automatically just like the viewdidLoad: method gets triggered when you navigate from one view controller to other. Please guide me on how could I do that.
Hoping for the best possible Answer
Thanks in Advance
You are correct, viewWillAppear is a little special, it is usually called automatically but in some cases including when you are adding a view controllers view manually (view addSubview:), and also when adding this as a view controller to a UITabBarController or UINavigationCnotroller (of which you have both !) it doesn't get messaged.
This however is only for the root view, as you navigate (maybe with a navigation controller) back and forth, that root view's viewWillAppear will get triggered as some point.
In short, if you need to implement something in viewWillAppear in these cases, you should message it yourself when you know it's going to be presented. You can handle this case in your view controller, check out the following article about the matter:
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
Good luck.
You should check UITabBarDelegate then look for the method:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item.
Description: Sent to the delegate when the user selects a tab bar
item.
In some apps that have a tab bar controller, each tab also needs a nav controller before a view can be added:
[[[_mainTabController topViewController] navigationController] pushViewController:renewalScreen animated:YES];
Do you mean 4 tab items on a tab bar, rather than '4 tab bars'? If you have a tab bar with tab items, the viewWillAppear: methods absolutely should be called by the system as the tabs are selected by the user. You could have other issues that are causing the problem.
You didn't forget to call [super viewWillAppear] somewhere?
Try using the viewDidAppear method instead.

Is there any way to have a tab bar switch views without using a tabBarController?

I have an app with a navigation controller that I would like to add a tab bar to. Does anybody know if its possible to say something like if the fist tab is selected show view1 if tab 2 is selected show view2? If theres code for that then I would be good to go. Any help is appreciated. Y+Thanks
According the interface guidelines, a tabbar should always be at the top level of the app. In other words, you should have a tabbar and then have a navigation controller inside each tab.
If you need to display views as with a tabbar but not at the top level of the app, use a segmented control. Users will understand they are choosing alternate views but they won't be confused about where in the app they are.
You shouldn't be using a UITabBarView without a UITabBarViewController.
Why do you not want to use a TabBarController?
Otherwise you can simply add a tabbar and implement the UITabBarDelegate protocol to react to changes. Which is essentially implementing your own TabBarController.
You will need to create a Tabbar and set the delegate to an object that implements the following method, where you can switch view based on the selected tabbarItem:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
int index = [tabBar.items indexOfObject:item];
switch (index) ...
}

Iphone UINavigationController onchange event

i have an app that uses a navbar. What i want to acomplish is make it transparent when i push in the last view from the nav sequence, and make it opaque when i click the back button on the nav
i tried with on dealoc, but it doesn't work. My view is an UIScrollView not an UiView, but i guess that makes no difference.
As i see it, eighter i have to control the events on the nav bar, and see the type of the view with a loop or trigger some event on the "unloading" of my current view
when i push in the view i do a
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
and when it pops out i need the
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
Pushing and popping a view with UINavigationController or UITabController will call the view
{Will,Did}{Appear,Disappear} methods so I think you need to hook into the child view's ViewWillDisappear.
I'd architect it so that top level navigation controller sets itself as the childs delegate, and the child calls its delgate with an "I'm unloading" type function where you change the navbar style.
Actually the best way for this is to use UINavigationControllerDelegate. I extended UINAvigationController and set the delegate to self and used one of the methods of the UINavigationControllerDelegate protocol.
You can't really depend on dealloc to ever get called, much less when you want it. That should only be used to release retained objects.
I think you should be able to add the barStyle changes in the viewDidAppear and viewDidUDisappear methods of your view controller.