I need to have such functionality in my app as "add to favorite". I have UITableView with cells, where cell refer to DetailViewController that contains UIImageView. So I need to make such option, when user presses button on the DetailViewController, it goes to FavoritesTableViewController and saves it there.
I have looked through a lot of questions like this, but I can't figure out what to do as I am newly to iOS programming.
Should I use NSUserDefaults? How to use NSUserDefaults? And If I use it, how can I load saved data in another view controller?
I have not so many recipes (app of recipes), so can I use plist? Also I have UIImageView, is it possible to use plist with UIImageView?
If your recipes don't have identifiers, add them. This could be the name, or the associated image name, but it must be unique and it can't change. This needs to be stored in the recipe data (vehicular I assume is an array of dictionaries).
When you add a favourite, save the identifier in an array in user defaults. The identifier should be a string or a number. Each time a favourite is added or removed, get the array from user defaults, mutableCopy it, edit it and then save it back to user defaults.
For the favourites display, pass the full list of recipes (or load it) and then filter it to remove any where the identifier is not in the favourites array.
Related
i have a table view and it contains an add button on navigation bar,click the button will show the add text page,i have already saved the text into the coredata and it will show on the tableview.
then,click the added tableviewcell will show the photo list page ,click the take photo button will add images into the photo list.
i have created one entities that save the text,but i don't know where to save the images,because the save process is not at the same time , and i have to use 'list.count' to show the saved text on tableview.should i create a another entities to save the images?if so ,how can i save the photo list to correspond cell with coredata?
The entity that stores your text should also have a to-many relationship to a photo entity. I assume the photo entity would just hold a relative path string (relative to some directory in your app such as the Documents directory).
Your photo list view controller could just be given the managedObject representing the named photos list during prepareForSegue so that it can access the list of image paths and add to the list.
Advanced tip: It'd actually be cleanest to abstract your model classes from CoreData by using protocols, and to use an ID such as a guid assigned to each named photos list entity. Then pass that ID between your view controllers, along with a reference to your model as a protocol (aka dependency injection).
I have a problem. First I sended information from textfield with prepareForSegue. I sended from WelkomViewController to TableViewController. There I put the data in a NSMutableDictionary. It's a person and his values. Then I put the person in another NSMutableDictionary for multiple persons. In the tableview I create a list with only the full name of all the persons. And with a click on the row I want to give a new view with the details of the person that the client clicked on. But I can't send the data with prepareForSegue it seems.(see image)
What do I do wrong? Thx for every reply!
project
You're trying to use a dictionary like an array, which doesn't work (obviously). You should not count on a fixed order for [self.personen allKeys], it can change at any point during runtime, which would result in the wrong person being passed along.
You need to use a mutable array as your storage vessel for people names, then address them by the row of the index path.
First of all you need to use NSmutablearray to save data of people so make sure that self.personen is an NSmutablearray then you need just to use ObjectAtindex function to get the selected row .
vcGevensView.persoon=[self.personen objectAtIndex:indexPath.row];
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 have a sidebar menu in my application (like facebook's one) and currently I have hard coded the categories of my sidebar. My question is the following : what is the best place to store the data of that menu?
Hardcoded like I have done actually?
SQLite database?
plist file?
I am asking that because I would like to keep in memory in which menu I am, and I wonder if database would not be the better way to do that?
Thanx in advance
If you just mean the categories of the menu itself, then hardcoding is fine depending on how likely they are to change. But if it's like facebook and they don't change, then it's fine.
In terms of the content that is displayed when you tap a menu item, that's different. There I'd recommend either a SQLite database, or better yet use CoreData to manage it for you.
If you have a view controller manage the state of that menu, you can keep in there which menu item you have selected, keep a list of items to display etc and that's fine, no need for a database there really. What I would suggest though is something flexible so that you could easily add new items.
For example one app I worked on, I created an array of NSDictionary objects that each had a title, image, and selector. When it came to rendering the list, I simply looped through the list, created a new item with the title and icon, and when the user tapped in called the selector. This way, if we needed new menu items, I could just add a new item to the array and that was it.
I had this array hard coded in the controllers initialiser, but you could if you wanted serialise this into a plist file, but that's just a preference thing
Use Plist or hard coded dictionary as its not relevant to save this in sqlite or coreData.It is not efficent to save this in database as to fetch each time you need to do database operation.
This data will not take too much memory so you can hardcode as you did and keep in memory.I think it is also on your controller that each time on side menu it remains in memory or each time you press button it will load.If it is not loading each time than your menu categories remain in memory.
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.