title: Problems when adding key-value pair to plist file in iOS
body: <p>I have a view controller in an iphone app that adds a key-value pair to a plist file. It then displays the entire plist in a view controller with a table view. The problems I'm having are that it will only display the values in the iPhone simulator and it will only display the new key-value pairs if I completely restart the app.</p>
  
  <p>NOTE: The plist file is supposed to be added to the app's resources directory
  UPDATE: the code below is the solution to my question, additionally, to view the new entries in the plist, I implemented a refresh button that basically ran the section in viewDidLoad.  </p>
  
  <p>The code for the view controller that adds the key-value pair is below: </p>
  
  <pre><code>- (IBAction)addAction:(UIBarButtonItem *)sender
  {    
      NSString *myFile=[[NSBundle mainBundle] pathForResource:@"File" ofType:@"plist"];
  
      dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:myFile];
  
      NSArray *docDir=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
      NSString *filePath=[docDir objectAtIndex:0];
      NSString *plistPath=[filePath stringByAppendingPathComponent:@"File.plist"];
  
      //Check plist's existance using FileManager
      NSError *err=nil;
      NSFileManager *fManager=[NSFileManager defaultManager];
  
      if(![fManager fileExistsAtPath:plistPath])
      {
          //file doesn't exist, copy file from bundle to documents directory
  
          NSString *bundlePath=[[NSBundle mainBundle] pathForResource:@"File" ofType:@"plist"];
          [fManager copyItemAtPath:bundlePath toPath:plistPath error:&amp;err];
      }
  
      //Get the dictionary from the plist's path
      dictionary =[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
      //Manipulate the dictionary
      [dictionary setObject:textContent forKey:textName];
      //Again save in doc directory.
      [dictionary writeToFile:plistPath atomically:YES];    
  }
  </code></pre>
  
  <p>This is the code to display the plist in a table view in the other view controller:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Initialize table data
  
      NSArray *docDir=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
      NSString *filePath=[docDir objectAtIndex:0];
      NSString *plistPath=[filePath stringByAppendingPathComponent:@"File.plist"];
  
  
      dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:**plistPath**];
      verses = [dictionary allKeys];
  
      [self.mainTableView reloadData];
  
  }
  </code></pre>
  
  <p>Thanks for all your help!</p>