一位朋友和我正在拟定一份灰色清单,并对[速读书重载数据]有一些麻烦。 我们重新在册子中储存了我们的灰色清单,并增加了一个子目。 当你离开该次调查以返回名单时,清单没有包含新项目,尽管我们正在更新该清单,并鉴于WillAppear呼吁重载数据。 但它的确发挥了作用;如果我们回到所有清单的总清单,然后回到我们刚才增列的项目清单中,那么这些项目就会显示出来。 同样,我们要删除名单上的项目,只选择行文,在项目旁边贴上一张支票。 尽管我们重新在选择行文时也要求重新载荷,但清单却自动更新。 同样,如果我们回到主名单,然后回到个人名单上,变化就显示出来。 我进行抽查,在尼布案卷中,代表和数据来源与档案所有人有正确的联系。
The Code for the viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// THIS IS WHERE YOU PASS THE VARIABLE
iGrocerAppDelegate *passTest = [[UIApplication sharedApplication] delegate];
NSString *listName = [passTest passList];
[passTest setPassList:listName];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *fullListName = [NSString stringWithFormat:@"%@.plist", listName];
NSString *file = [[paths lastObject] stringByAppendingPathComponent:fullListName];
self.list = [[NSArray alloc] initWithContentsOfFile:file];
[listTableView reloadData];
}
and didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:
indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
int row = [indexPath row];
NSString *deleteItem = [self.list objectAtIndex:row];
[self.itemsToDelete addObject:deleteItem];
// RECEIVE PASSED VARIABLE
iGrocerAppDelegate *test = (iGrocerAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *listName = [test passList];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *fullListName = [NSString stringWithFormat:@"%@.plist", listName];
NSString *file = [[paths lastObject] stringByAppendingPathComponent:fullListName];
//NSMutableArray *groceryLists = [[NSMutableArray alloc] initWithContentsOfFile:file];
//NSMutableArray *groceryList1 = [[NSMutableArray alloc] initWithContentsOfFile:file];
NSMutableArray *groceryList = [[NSMutableArray alloc] initWithContentsOfFile:file];
NSMutableArray *removeFromList = self.itemsToDelete;
int itemCount = [removeFromList count];
NSLog(@"Count: %d", itemCount);
for(int i=0; i < itemCount; i++) {
NSString *item = [removeFromList objectAtIndex:i];
NSLog(@"%@", item);
[groceryList removeObject:item];
NSLog(@"Middle ARRAY: %@", groceryList);
//[groceryList addObjectsFromArray: addToList];
}
NSLog(@"FINAL ARRAY: %@", groceryList);
if(![groceryList writeToFile:file atomically:YES]) {
NSLog(@"unsuccessful");
} else {
NSLog(@"successful");
}
NSLog(@"file name: %@",file);
self.list = [[NSArray alloc] initWithContentsOfFile:file];
NSLog(@"updated grocery list: %@", self.list);
[listTableView beginUpdates];
//[listTableView reloadData];
[listTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[listTableView endUpdates];
printf("list table view reloaded");
}
Any help would be much appreciated! Thanks in advance!