Iphone tab bar control - iphone

I have a tab bar control and need a method in the view controller of each tab to get called once a tab bar item is selected.
Does anybody know which method gets called?
Thanks

You can implement a UITabBarControllerdelegate and then you have:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
where you retrieve the viewController on which you can call whatever method.
You also get the tabBarController that contains all the viewControllers on which you could iterate to call the method

viewWillAppear:(BOOL)animated
viewDidAppear:(BOOL)animated

Related

Clicking on tab always open rootviewController

I am creating a tabBarApplication in which there is one tab on which camera opens.After clicking on the use tab of the imagepicker I push a new class.
Now my problem is when I again press camera tab that class gets open AND I want that camera should gets opened basically my rootviewcontroller of that tab.
Any suggestions will be appreciated.
Thanks in advance!
You can implement this delegate method, when the selected view controller is camera controller, you can popToRootViewController.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

Puzzle about TabViewController?

I have made an app in which i have 2 tabs.and there are navigation controller in them,
The issue is that once i click on the tab bar and there is navigation bar and the view changes as i drill down.But when i go to the second tab and then come back to the 1st tab then it opens the view which was there previously when i changed the tab.So it retain the view whereas i want that that tab should start up with the same first initial view.
From where we can do this by info.plist or what..>?
Thanks in advance ...
Adopt UITabBarControllerDelegate protocol and implement tabBarController:shouldSelectViewController: method.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)controller {
[(UINavigationController *)controller popToRootViewControllerAnimated:NO];
return YES;
}
This assumes that all tabs have navigation controllers.
That's not how tab view controllers work. You can implement this method in your app delegate (after making it the delegate for the UITabeBarController)....
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
Then call a reset method (or similar) on your view controller to pop back to the root view controller.
This is not how you normally work with UITabBarControllers however....
You can implement
- tabBarController:didSelectViewController:
in the delegate of the UITabBarController and then call
– popToRootViewControllerAnimated:
on the UINavigationController

Get callback/execute some code when a tab on Tab Bar is clicked

Alternatively, I could use something like viewWillAppear, only switching tabs doesn't call viewWillAppear - IF I can access selectedItem or selectedIndex reliably from there.
The goal is to re-use a similar table view, with 3 tabs filling the table with differently filtered data.
I tried overriding didSelect and using the app delegate as UITabBarDelegate, but got the error 'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'
The tab bar controller, rootCt, is in the app delegate and works correctly.
So that's the trick I'm looking for - getting a notification from the root (tab bar) controller when the index has changed. Ideas?
Try implementing an UITabBarController delegate. It has a method similar to the didSelect: method offered by UITabBar delegate:
tabBarController:didSelectViewController:. It will be called after the user has selected another tab.
See: UITabBarControllerDelegate Protocol Reference
tabBarController.tabBar.selectedItem.tag
It will give you the tag of current selected tabbar index
If you are using tabBar den
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
is the delegate method that gets called when tabbar is selected.
happy iCoding...
You can use the delegate method of UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
and in that you have self.selectedIndex will give you the selected index.
I don't usually do this kind of thing (answer my own question). But here goes.
For example, if I click tab 2, then tab 3, then tab 2 again, viewWillAppear for that view is called, but the didSelectViewController method is not - and selectedIndex is not changed!
It appears as if selectedIndex is only updated if a view is loaded, not if the view is already loaded and simply appears.
I did some testing, and unlike selectedIndex, the tab bar's selectedItem is correctly updated (in viewWillAppear for the view in the clicked tab) even if the view is already loaded. By putting f.ex. the tabs' titles in an array, the matching index can be looked up.
So I will omit the didSelectViewController and won't need a UITabBarController, I only need to connect the UITabBar to an IBOutlet and use [myTabBar selectedItem].title to initialize correctly in the re-used view's viewWillAppear.
If someone offers a more generic/useful/simple solution I'll gladly mark that! Will check back in a few days and mark this if not. Just glad I made it work :)

How to push uiviewcontroller over tabbarcontroller

I have a tabbar app. each tab has uinavigationcontroller. but all navigationcontroller's Shows Navigation Bar value is NO.
i control the which navgation control is active in
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
event in AppDelegate. Then i the user taps a row in a table in a tab i call the same method (openDetail)in appdelegate. i want to push DetailViewController full screen, not in tabs controller. i tried some ways but never worked. so i push it as a modalview.
[currentNavController presentModalViewController:detailVC animated:YES];
how can it come/go from right side.
i just want it to work like normal rootviewcontroller. but new controller should come over tabbarcontroller like USA Today app.
present the view controller like this
[tabBarController presentModalViewController:detailVC animated:YES];

Refresh the tableView when clicking on the tabBar

I want simply to refresh my tableView (on the iPhone) when I click on the related button in the tabBar...
So, I think this has to be done this way :
[self.tableView reloadData];
Right ? And done in the
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
But I don't know how can I send the message reloadData to the tableView from the tabBar controller... Could you help me please ?
In your UITableViewController class, implement the viewWillAppear method and call reloadData from there.