How to make pressing a selected tab bar item reload my view - ios

I have a view contained in a tabbarcontroller. When a user clicks on one of the items I load data into that view. However, if they click that item again I want to reload the view again.
So far I am running the didSelectViewController method in my tabbarcontroller and from there I popToRootViewControllerAnimated. However it appears that popToRootViewControllerAnimated doesn't execute the viewdidload, viewwillload, or viewwillappear methods, so I am stuck as to how to reload...

While it may not be UI friendly to refresh an already selected tabbar item (user already selected that item and it shows it as selected. They would then expect to pull down to refresh), have you tried adding [viewController.view setNeedsDisplay]; in your didSelectViewController?

Related

How can i reload/refresh the current tab in the UITabBarController in Swift?

I have a UITabBarController with 2 tabs (map & tableView) like the image below.
the problem here i need by pressing the refresh button the tabBar refresh/reload the current tab if it is the map, so refresh the map, if it is the tableView, so refresh the tableView.
just like for the first time when the tabBar instantiate the first tab at the beginning of launching the tabBar.
//i need something like that
self.currentTab.reload()
Create a function which contains refresh related code for all the required components and whenever the reload button is clicked then call this function for current view controller. Initially call this function in viewDidLoad(). If every time you navigate to this view controller and you need refreshed data then call this function in viewWillAppear()
Hope this helps.

reload collection view by press back bar button item

I have a collectionView in my app that when the user taps one cell of it, the collectionView will reload data, in detail, I have an album that it could contain another album when user choose one of them it shows albums inside of that.
Now I want when user click on backBarButton the past data appears on collectionView (super-albums), but now backbarButton shows the past VC.
I use navigationController and show module segues between VCs.
Q: How should I implement that?
If your changing view on collection cell press. you can reload the collection view on viewWillAppear.

Refresh view controller after tab is selected

I have implemented a UITabBarController for iOS. When I click on the third tab, I need to programmatically go to the first tab .. this works fine with
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
But when the tab time is selected and the appropriate view controller appears, I need to first refresh it. I have tried calling didSelectViewController, but that only seems to work when the tab is pressed. I need to call a method after the focus of the view appears.

UITabBarController selectedIndex lagging by one click

I have been using the tabBarController selectedIndex to determine whether a navigation bar should be displayed. Everything was working fine for most of today, but now this line of code:
self.tabBarController.selectedIndex
is giving the last selected index rather than the currently selected index. I am running this line of code in viewWillAppear to make sure that a particular view which has index 1 in the tabBarController will not show its navigation bar on its first view.
But it's reporting 1 click behind. For example, when I click on the 2nd index and then the 1st index, my last click shows up as having selected the view controller at index 2 even though I have just clicked on the view controller with index 1. Also, the selectedIndex is always listed correctly the first time I click on any view controller but never correct after the first time it is viewed via the tabBarController.
I've looked over the tabBarController class reference, but it seems like this selectedIndex property should be straightforward. What am I missing?
The problem you have is that viewWillAppear is called before the index has actually changed.
First, tabBarController shouldSelectViewController -> viewWillAppear -> tabBarController didSelectViewController -> viewDidAppear.
I have a similar setup where I reuse ViewControllers across different tabBar indices. I did not want to check for the selectedIndex in the viewDidAppear even though that would fix the problem.
What I did to fix the problem was to go by a tag. Both ViewControllers have different UINavigationController and I set the tag of one navBar to 1. Every time I need to know which Controller is active I now check for the tag.

Reload Table when View Controller has been navigated backwards to

I have a table in one view controller and a "+" button to add to the table. The "+" button brings you to the next view controller, which contains a dialog and a "Save" button to add a new item to the table. upon clicking the save button i use the function
[self.navigationController popViewControllerAnimated:YES];
to bring it back to the previous viewController with the table. The table does not repopulate by itself and until i go back one more view controller and then reopen (which re-initializes it)
So i was thinking i could use this function
[self.tableView reloadData];
to reload it upon opening the viewController when i have navigated backwards to it.
Is there a function that is called when a viewController is viewed after clicking the back button on the next viewController?
Any help is greatly appreciated!
It sounds like you want viewWillAppear. UITableViewController's do some stuff already in viewWillAppear but you need to subclass in order to have it reload the table as well.
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html

Resources