making array data able to be favorited and loaded in a table
hello i have an array that features data in an array of arrays. its like the items in format root array rootArray = [[NSArray alloc] initWithObjects:@"1", @"2", nil];
i want to knw what action to give a uibutton in order to be able to change a boolean value to is_favorite for that cell and make it show in the favorite table.
so i want to have an -(IBAction) makefavorite
//i have no idea how to implement this however to make the selected detailview controller and also its previus cell that was selected load in the favorites table.
furthermore i heard of using the is_favorite boolean to make items appear in a favorite view however i heard that only开发者_高级运维 applies to databases.
hope im more clear now
thanks
translation attempt:
Hello, I have an array of data and I show the user some object out of that array in a "detailed view" so to speak. Once the view shows some object in that array to the user, I want the user to have the option of saving that object to their "Favorites" by clicking a UIButton. I would then like all of these "favorites" loaded into a UITableView with each item in the favorites array representing an individual table view cell. So possibly I could store all of these "favorite" items into a set of NSUserDefaults each time a button is pressed?
Could anyone elaborate more on how I could implement such a system? I am very new to this and my English is not very good. Thanks!
Okay, based on what I think you're saying, you're trying to add a button to mark some objects in an array as favorites?
You could create a model class that represents each object and give it a boolean property favorite
or something, then simply do something like ([[rootArray objectAtIndex:someIndex] set] setFavorite:YES];
in your makeFavorite
method. Alternatively, you could just use an NSDictionary
with keys for the text and whether or not it's marked as favorite.
As for storing the favorites, NSUserDefaults
is not appropriate for that. (NSUserDefaults
should be used for anything related to user settings; basically, anything that you would expose in the Settings app). Instead, you would want to write your array to a file in one of the writeable folders when the application is suspended, and restore the array from the file when the application becomes active. (You could also use sqlite or some other form of storage if you wanted, but it sounds like you're storing relatively simple data so this isn't necessary).
精彩评论