Reload Table when View Controller has been navigated backwards to - ios

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

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.

Swift - Remove View Controller from Navigation System

The best way that I can describe it is through and image, so i drew it out HERE. So, what happens is that in my table view, I press a button to add/edit information. When i am done, I press "Finish" at the bottom, which performs a simple segue back to the table view.
The Problem: Once back in the table view, the "back" button will now take me to the edit info page(which I just left) rather than the VC that came before it.
Is there any way to remove the Add/Edit info VC so that when I press "+" and "Finish" The back button will ignore the Add/Edit page?
Thank you for your help.
EDIT: . As you can see, when you press a button on the Table VC (lefT) it will take you to the right VC. Then, when you press finish at the bottom, it will perform a segue(no code, just a control-drag segue). The problem is still that the text message VC's back button will now direct back to the right VC, rather than the one preceding it (left)
I suppose you have a UITableView inside a UINavigationController since you have a back button, so:
User Tap Edit button: Push EditViewController in your UINavigationController
User Tap Finish from EditViewController: Save data, pop manually EditViewController and call reloadData of your UITableView
You would have to embed your complete sequence of view controllers in the navigation controller. This would maintain a stack of all the views that you would segue to. It will also give you a bcak button to go back to previous view. Alternatively, you can call the method popViewController() on navigation controller object to programmatically go to previous view. I hope that helps.

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

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?

navigation Done item not working

in the top view of my view controller (the last table view controller) has an add navigation item. i added a view controller object from the objects library and i ctrl + dragged from the plus button to the view controller. i tried the app and it works fine but i can't go back to the previous controller when i reach the last controller. since the last controller connected (by segue) to the plus button, i can't have a navigation bar on top. so i added one and added an navigation item called it Done. i created an IBAction method in the class that the last controller subclasses which have the following code:
[self.navigationController popNavigationControllerAnimated:YES];
However, when i run the app and press the Done button to go back, it doesn't work although i feel like what i did is totally legal.
If you would have made the final view controller segue a Push segue, you'd still have the navigation bar with a back button. It makes sense since you're adding a record that you'd want a modal view.
You can dismiss the current modal view with the following code:
[self dismissViewControllerAnimated:YES completion:nil];
Generally, you should use delegation and dismiss it from the presenting view controller. However, I think it's fine to dismiss yourself if you're using storyboards, segues, and ARC.
Did you create a Bar Button Item and assigned its 'selector' callback?

displaying UIPickerView over current ViewController xcode

Here is my current problem. I have a UIViewController setup with its data and everything on a small sized view controller. What I am trying to see is if it is possible to connect that to a separate view controller. For example I have a view controller that has a user click a button. Upon pressing the button the UIPicker ViewController would pop up from the bottom and I could go from there. I know how to enable this if the picker is on the same view controller. However, I have no idea how to if its on its own ViewController. Any ideas?
One way to do this would be to put the picker view on the same view controller and make it hidden, and, when they press the button, unhide it or load the other view controller when they press the button; this will display the other view controller, not what's on the current one.

Resources