English 中文(简体)
[表View reloadData];
原标题:[tableView reloadData]; doesn t reload until navigating back to root controller

一位朋友和我正在拟定一份灰色清单,并对[速读书重载数据]有一些麻烦。 我们重新在册子中储存了我们的灰色清单,并增加了一个子目。 当你离开该次调查以返回名单时,清单没有包含新项目,尽管我们正在更新该清单,并鉴于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!

问题回答

Solved.

仅需要:

[self.tableView reloadData];




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签