I am calling data from a plist (copied to documents) which has a 0 or 1 value depending on whether I want a tickbox selected or not selected. The code in the cell.m file is as follows but I can't seem to get it to alter whether the tickbox is selected or not.
Main View code:
#import "ffguideViewController.h" #import "booksCell.h" @interface ffguideViewController () @end @implementation ffguideViewController { NSArray *title; NSArray *thumbnails; NSArray *price; } - (void)viewDidLoad { [super viewDidLoad]; // Find out the path of books_star.plist NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"books_star.plist"]; // Load the file content and read the data into arrays NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath]; title = [dict objectForKey:@"title"]; thumbnails = [dict objectForKey:@"thumbnail"]; price = [dict objectForKey:@"price"]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [title count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *books_starTableIdentifier = @"booksCell"; booksCell *cell = (booksCell *)[tableView dequeueReusableCellWithIdentifier:books_starTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"booksCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } cell.titleLabel.text = [title objectAtIndex:indexPath.row]; cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]]; cell.priceLabel.text = [price objectAtIndex:indexPath.row]; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 104; } @end
Cell code:
#import "booksCell.h" @implementation booksCell @synthesize titleLabel = _titleLabel; @synthesize priceLabel = _priceLabel; @synthesize thumbnailImageView = _thumbnailImageView; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) {} return self;} - (void) awakeFromNib { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"books_star.plist"]; // Load the file content and read the data into arrays NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath]; NSString *checked = [dict objectForKey:@"check"]; NSLog(@"%@", [[dict objectForKey:@"check"] class]); NSLog(@"Checked %@", checked); int checkedINT = [checked intValue]; NSLog(@"CheckedInt %d", checkedINT); if (checkedINT == 1){ checkedImage.image = [UIImage imageNamed:@"check_on.png"]; } else { checkedImage.image = [UIImage imageNamed:@"check_off.png"];}} - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end
plist: