Refresh the tableView when clicking on the tabBar - iphone

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.

Related

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

How to know when a tabbar item that is in the superview is clicked from a sub view

I have an application which has a tabbar to navigate through 5 views.
I have a uitableview in one of these 5 views (my viewcontroller for this view is the table delegate).
Now I want to reload my table view every time the user goes to another view and comes back to this view using a method called reinitializeAndReloadTable however I don't know when to call it..
Is there a method which lets my view know that the tabbar item related in its superview has been reclicked?
Thanx
tiw
From what I getting you want to know when you select specific tab ?
You can use this method. add this inside App delegate. it gets called everytime tab is clicked
then you can look for the specific view controller index and reload table.
Create a BOOL here to identify other than tableview is clicked.. use it to call reload method.
` // Optional UITabBarControllerDelegate method
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ((self.tabBarController.selectedIndex == 1)
//put your code here.
`

Iphone tab bar control

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

uitableview delegate methods are not called

I've got the problem that tableview methods are not called the first time the tableview is shown.
If I switch back to the previous view, and then click the button to show the tableview again, the methods are called this time.
I should say that I show an actionsheet while the tableview is loading.
The actionsheet I call in the ViewWillAppear method.
i fixed it by adding [self.tableView reloadData] after dismissing the actionsheet. i don't know if it's the proper way, but it somehow works.

UITableView custom popping

Okay, I made an app that has a list of items as a main view, and when you select an item it pushes a detail view controller. In this detail view controller you can switch between items. I want to be able to push a view, scroll a few items, and pop the view as if the current item was initially selected. I want to push a view, and then when i pop it, i want it to look like a different view was initially pushed.
Any ideas on how to do this?
Take a look at UITableView's selectRowAtIndexPath:animated:scrollPosition: method. You can call it from within your view controller's viewDidAppear method to achieve the illustrated effect, I believe.
Consider that this is probably not what you really want to do. Leaving a table cell highlighted after a return from a detail view has been condemned by Apple and will be jarring to users unless you have a really good reason for it.
So far, to achieve this effect, I have used this to mask the original UITableViewCell from highlighting.
I have added this in the -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated method
[self.tableView selectRowAtIndexPath:selectedRow animated:NO scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:selectedRow animated:NO];
Where selectedRow is the Index Path of the original cell selected. I have also added the code below to scoll to and highlight the correct UITableViewCell.
[self.tableView scrollToRowAtIndexPath:tempPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
[self.tableView selectRowAtIndexPath:tempPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
[self.tableView deselectRowAtIndexPath:tempPath animated:YES];