tableview will not update on phone

后端 未结 3 1854
忘了有多久
忘了有多久 2021-01-27 01:30

If this is a repost, I apologize, but I have been scouring the net and cant seem to find anything that works. I have a list of workouts that I display in a tableview that are ga

3条回答
  •  日久生厌
    2021-01-27 02:13

    If I understand right your code you load plist file only in viewDidLoad, but most likely this function called only when you first time load your view. To make it work you should load plist in viewDidAppear. Something like this:

    - (void)viewDidAppear {
      NSBundle *bundle = [NSBundle mainBundle];
      NSURL *plistURL = [bundle URLForResource:@"CrossfitWOD" withExtension:@"plist"];
    //put the contents of the plist into a NSDictionary, and then into names instance variable
    NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:plistURL];
    self.names = dictionary;
    //take all the keys in the dictionary and make an array out of those key names
    self.keys = [self.names allKeys];
    
    for (NSString *nameCheck in keys){
        self.details = [names valueForKey:nameCheck];
        if ([[self.details valueForKey:@"Type"] isEqualToString:@"The Benchmark Girls"]) {
            [buildBenchmarkGirls addObject:nameCheck];
        }else if ([[self.details valueForKey:@"Type"] isEqualToString:@"The New Girls"]) {
            [buildTheNewGirls addObject:nameCheck];
        }else {
            [buildHeroes addObject:nameCheck];
        }
    }
    
    NSString *filePath = [self dataFilePath];
    NSMutableDictionary *savedWorkout = [[NSMutableDictionary         alloc]initWithContentsOfFile:filePath];
    self.savedNames = savedWorkout;
    self.savedDFGWorkouts = [[savedWorkout allKeys]     sortedArrayUsingSelector:@selector(compare:)];
    
     [self.tableView reloadData];
    
    }
    

提交回复
热议问题