У меня есть небольшая проблема с Приложением, которое я разрабатываю в данный момент, но я начинающий, прежде всего немного информации о том, чего я пытаюсь достичь.
У меня есть plist, который заполняет NSMutableArray, который содержит много значений, каждое из которых имеет строку и BOOL внутри, я могу заставить программу сохранить копию файла при открытии приложения и загрузить данные в табличное представление вместе с вспомогательный вид галочки.
теперь флажок работает нормально, и вы можете выбирать различные элементы, и флажок появляется только на этих элементах, но ни на одном другом, и если вы просматриваете журнал, детали для каждого из элементов проверяются, BOOL изменяется, но когда я прихожу, чтобы сохранить во второй раз состояние галочки не сохраняется, когда я открываю приложение во второй раз, оно просто сохраняет его как 0 каждый раз.
вот мой код, любая помощь будет признательна.
Спасибо
Брэд
- (void)viewDidLoad {
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"CustomChecklist.plist"];
success = [fileManager fileExistsAtPath:filePath];
NSLog(@"STATUS OF SUCCESS %d",success);
if (!success) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"OriginalChecklist" ofType:@"plist"];
success = [fileManager copyItemAtPath:path toPath:filePath error:NULL];
self.dataArray = [NSMutableArray arrayWithContentsOfFile:filePath];
NSLog(@"IF STATEMENT CREATING THE FILE");
}else {
self.dataArray = [NSMutableArray arrayWithContentsOfFile:filePath];
NSLog(@"IF STATEMENT READING THE FILE");
}
NSLog(@"location information %@", filePath);
[super viewDidLoad];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCustomCellID = @"MyCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.text = [item objectForKey:@"text"];
[item setObject:cell forKey:@"cell"];
BOOL checked = [[item objectForKey:@"checked"] boolValue];
UIImage *image = (checked) ? [UIImage imageNamed:@"checked.png"] : [UIImage imageNamed:@"unchecked.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame; // match the button's size with the image size
[button setBackgroundImage:image forState:UIControlStateNormal];
// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
return cell;
}
- (void)viewWillDisappear:(BOOL)animated
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savePath = [documentsDirectory stringByAppendingPathComponent:@"CustomChecklist.plist"];
NSLog(@"View Will Disappear SAVE location information %@", savePath);
[dataArray writeToFile:savePath atomically:YES];
}