I have been searching how to send data between multiple view controllers but its only seem to be possible to send from one at a time?
I have five view controllers and I want to add text in to the TextFields I have in four of the five of them.
When I am in the last view I want to get the data from the four previous controllers.
You should use the NSUserDefault class.
With the NSUserDefaults class, you can save settings and properties related to application or user data. With NSUserDefaults you can save objects from the following class types:
NSData
NSString
NSNumber
NSDate
NSArray
NSDictionary.
I am 100% sure this link could solve your problem..
http://code.tutsplus.com/tutorials/ios-sdk-working-with-nsuserdefaults--mobile-6039
Related
I have an array of users
var selectedUsers = [User]()
users are added to this array as they are selected in a UITableView (see screenshot: https://www.dropbox.com/s/uk03mhgi3x4jesy/File%2006-10-2015%2C%2018%2003%2044.png?dl=0)
What I'm having difficulty with is when I press back and then reload the view controller, all the checkmarks disappear.
Is there anyway I can keep track of the selected cells?
Thanks in advance
You could use a delegate to pass a array between the two viewcontrollers. For example, each time you select a row, you can store the userId's associated with the row, in the array. So if you were to press back and then open the view with the UITableView, before you load the UITableView, you can first check if there is an array being passed to the viewcontroller containing the UITableView / if there is an array, check if the count is greater than 0. If the array is not empty, then use a for loop to cycle through the array of users being displayed with the array being passed containing all of the previously selected id's, then add the check marks that match up to the Id's in the array.
Here is a tutorial that possesses a similar example: http://makeapppie.com/2014/08/04/the-swift-swift-tutorial-why-do-we-need-delegates/
The answer to this question is kinda dependent on what you want the application to do... Do you want the User selections to persist even if the app is closed? If so consider using NSUserDefaults or CoreData. Otherwise store the data somewhere that does not get blown away (maybe the root view controller of your application). You could for instance implement the delegate pattern on the view controller with the table view and pass the values to the container view controller.. Just some ideas.
So you can use class NSUserDefaults to save small amount of data. If you want to have persistent store so you have to use Core Data that helps you store you data with scheme you provide.
If you just want to pass data from one view controller to another view controller so you just need use delegation pattern or you can use method prepareForSegue where you can pass some data as well but you can't store this way, just pass.
If you make your question more detailed you will get more explicit answer.
I am developing an app for Apple watch. I am pushing a interface controller from another interface controller ,how to send more than one object between controllers in Hierarchical navigation style?
you can make a new array of any object with your objects contents inside of that array:
var array = [AnyObject]()
array.append(youobject1)
array.append(youobject2)
After that you can user the send the context to the second interface with this array.
You could be sending an array or a dictionary that contains the several objects you want to send.
There are two ways to do so.
First: Pass an Array or Dictionary (according to jastrada - Sorry, because of my low reputation I can't vote up)
Second: Make a global structure or class (with static values) and when going from one to another, initialize the class and give it values, and get the values back in the second view.
Both of them will cause the expected results.
Is there any other solutions in iOS for saving the NSDate in one ViewController and showing it in a label in another ViewController rather than NSUserDefaults? I have 2 viewControllers in my project which one of them is DatePicker and another is a normal ViewController with a label.I want to show the time with DatePicker chosen in that label and I use NSUserDefaults.I am curios is there any other solution for this matter?Thanks in advance.
Core Data can be used instead of NSUserDefaults. Core Data is better, though, for larger amounts of data, so for your case, NSUserDefaults is the best option.
Core data is great for relationships and has a nice interface for adding entities and relationships.
It uses key value coding (setValue:ForKey: like NSDictionary) and objects from core data are subclasses of NSManagedObject.
Here is a nice tutorial: http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started
You can use a singleton class (e.g. DataManager), and you could keep the selected date here if you have no direct segue between these 2 UIViewControllers. if you do, just add a property and set it when you present the controller. However, these won't persist between app launches, so for that you would need the NSUserDefaults
I have multiple ViewControllers all linked to an initial ViewController. Each of the extra ViewControllers acts as a 'tennis court', with player1 and player2's names entered into UITextFields, and then stored in an array.
Is it possible, using a UISearchBar on the initial ViewController, to search the name of a player stored in one of the various variables, and then for that result to link to the ViewController within which it appears?
Recall MVC.
You never store your data or model in any viewControllers. You store them in a model that may be an array, dictionary, or plist or even a database.
So you need to search from the model using your UISearchBar.
*If you show your code, we can correct them.
is it possible to declare an NSArray withobjects of view controllers?
I'm trying to use two buttons to call an array that will loop through and count through 20 different views.
Right now, my array works in calling and displaying multiple images in a single view application.
what would i do to create an nsarray of view controllers, so that every time the "next" action method is called, a new view is loaded, and essentially, counted through the array?
This is currently what I have listed in my array
-(IBAction)getNextView {
imageArray=[[NSArray arrayWithObjects:
[firstViewController.view],
[secondViewController.view],
[thirdViewController.view];
}
But I think i am missing a valid point of updating the mainview with the elements in the array...
Thanks!
UPDATE :
This is what I am trying to achieve...
yes why not, you can create an NSArray with objects of viewControllers