I have a problem. In my app I have an embedded tableview. Tapping a button (first button) it is showed a view with a textfield and a button (second button).
I want that what I write in the textfield of the second view, pressing the second button, get saved in an array. Than what is saved should be printed in the tableView. Every time I press the second button the tableView should be refreshed, so can it shows the updated array.
How can do it?
Thanks everybody
After saving it into your array you should call function on your tableView. For example you have connected your table view with your ViewController via IBOutlet named tableview. Than just simply call this, when you want to refresh your tableview.
tableView.reloadData()
And that is all.
Related
My Current Setup
ViewController3:
This ViewController has 18 TextFields stacked vertically. This is the “settings” screen where the user can add their default text (single words, comments or sentences). This view also has a save button to save using UserDefaults, which is working fine.
To access this view (settings screen) the user taps the settings button located on the main view (ViewController1) via a show segues. Once all editing done to the default texts (usually a once off and reused again and again), they tap the save button and then tap Done button to return to ViewController1.
ViewContoller2:
This ViewController has matching 18 TextFields (again stacked vertically), but each with a selection switch. If switch is active, means that TextField is selected. Out of the 18 TextFields which are stacked vertically, the user can select any given number of them.
The selected ones are then populated as a selected list of texts in the mail body of an email being sent from a Send Email button back on ViewController1.
ViewController1:
This is the main view of the app where the app will send off the email after entering desired text into a number of TextFields and it included the TextView that has the selected list of texts from ViewController2
Note: All transitions between ViewControllers are via show segues.
Question 1:
What code or how to write the code to enable the TextFields in ViewController2 to auto populate (copy or mirror) the text that has been entered it the TextFields in ViewController3?
Question 2:
How do get the selected TextFields from ViewController2 to show up in the body of the email as a list of items but vertically stacked on their individual lines?
Ok, let me see if I undestood.
VC3 is the settings view where you "register" the texts to be used at some point.
VC2 is the view that you select which texts you want to use/send/whatever
VC1 is the main screen, where you are displaying the texts you chose above
If you are using segues, I believe that your VC2 is not instanced when you are registering or changing data on the VC3. So, NotificationCenter is not an option like #dahiya_boy told.
If you are saving all the data on UserDefaults, can't you just load this data and apply on each TextField on VC2 when the user open the VC2 screen (probably on viewDidLoad )
Your second question... whats the problem?
If the problem is passing data between the VC2 and VC1, you can use NotificationCenter, or delegate.
If the problem is how to show it as a stack, so you can pass it as an array from VC2 to VC1 and appending everything using joined(separator:) and passing \n as the separator. (symbol for newline)
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.
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.
I have an app(my first) that has several view controllers.
VC1 - is an tableView with a name & image. (a list)
VC2 - is a View with name, image and two buttons. (list add/edit view)
Data passing between these two views works fine using protocols
VC3 - is a tableView with another list. (items for first list)
I have a Button on VC2 that segues to VC3.
So a user enters the first TableView and taps on a tableViewCell, it segues to the second View for editing that selected list. While in the second View(not a tableView) the user taps a button which segues to the third TableView to add/edit the items. Then the user taps the done button sending the user back to the second View.
This is my issue - how do I pickup/associate the list name from VC2 to VC3. When the user taps doneButton the items should be associated with that one list that the user was editing.
thank you, newbie
Here is a good tutorial from apple showing you how to do just that. The basic idea is that to add things to a table view. Have an array of objects in the VC1 that contains everything you want to show. Then pass that array to VC2 (which in turn passes it to VC3) using prepareForSegue. Here is a good segue tutorial.
For editing (moving and deleting cells), this had native support so you won't have to roll your own. The bottom of that tutorial link shows how to enable this.
The basic idea for deletion is that you want to remove the element from the array and then redraw the table view (VC1) without that element. Failing to keep the table view and array in sync will result in a crash.
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