ios - Checkbox in UITableView Cell -


I've written an app that lists the price of some books, a thumbnail, and the price of the other hand, all of which are called UITBL VUU And the data Plist file is taken from.

What I want to add is a checkbox in each cell that can be toggled if the user has a book or not and then store the checkbox status to use the app next time. What value back Is it possible to store in a Plist file or is there another way to do it?

Here is the code that I have done for the cell so far:

  @information ffbooksCell @ synthesize ffbooksLabel = _ffbooksLabel; @ Synthesis value label = _priceLabel; @ Synthesize thumbnailImageView = _thumbnailImageView; - (void) viewDidLoad {NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; NSString * Path = [Document Directory stringBapensing Path Companent: @ "F.F.book.plist"]; NSMutableArray * checkbox selected = zero; // documents tries to load the saved data from the directory, ([[NSFileManager defaultManager] fileExistsAtPath: path]) {checkboxSelected = [NSMutableArray arrayWithContentsOfFile: path]; } Else {// documents so no data is saved in the directory, we need to load data from the bundle NSString * bundlePath = [[NSBundle mainBundle] pathForResource: @ "ffbooks" ofType: @ "plist"]; Checkbox selected = [NSMutableArray arrayWithContentsOfFile: bundlePath]; } // // // check box to the book Toggle 0 if ([checkbox selected [0] [@ "checkbox"] boolValue]) {checkbox selected [0] [@ "checkbox"] = no; } And {checkbox selected [0] [@ "checkbox"] = @ yess; } // Note: The @ "checkbox" does not need to be in the original Plast // ... [checkbox selected text file: path atom: yes]; If (checkbox selected == 0) {[checkbox button set selected: no]; } And {{checkbox button selected from set: Yes]; }} - (IBAction) checkbox button: (ID) sender {if (checkbox selected == 0) {[checkbox button set selected: yes]; Checkbox = 1; } And {{selected from the checkbox button set: No]; Checkbox selected = 0; }} - (id) initWithStyle: (UITableViewCellStyle) style reuseIdentifier: (NSString *) reuseIdentifier {self = [super initWithStyle: Style reuseIdentifier: reuseIdentifier]; If (auto) {// initial code} returns itself; } - (zero) set selected: (BOOL) selected animated: (BOOL) animated {[Super set selected: selected animated: animated]; // Configure the view for the selected state} @end  

There are a lot of options Core Data to store data in Plast would be my choice. Learning how to use core data is worth investing. You can still use plist to populate your database.

Although yes to answer your question, you can store the data in Plast. . Value should be an array stored in the initial data bundle and dictionaries Here are some example code

  NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; NSString * Path = [Document Directory Stringbacking Pathcompany: @ "books.plist"]; NSMutableArray * Info = Zero; // If you try to load saved data from the document directory ([[NSFileManager defaultManager] fileExistsAtPath: path]) {info = [NSMutableArray arrayWithContentsOfFile: path]; } Else {// documents are saved because the data we do not bundle directory Ansstiing * Bndlpath = [[Ansbindl main bundle] Pthfor need to load data from resources: type @ "book type" @ "Plist "]; Info = [nsmutbale array array description resourcefile: bundle path]; } // // Toggle the check box for the book 0 if ([Info [0] [@ "checkbox"] Bull Valley]) {info [0] [@ "checkbox"] = no; } And {info [0] [@ "checkbox"] = @ yeah; } // Note: The @ "checkbox" does not need to be in the original flist [info writeToFile: path atom: yes];  

Update: I have created a summary for you to help load the data in the Table View Controller


Comments