Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete from uitableview + write to plist not working
    primarykey
    data
    text
    <p>i want to delete from uitableview and make it write to my plist. i'm pretty new to this objective-c iOS coding, so forgive me for mistakes</p> <p>Right now with my code it crashed with this :</p> <pre><code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (11) must be equal to the number of rows contained in that section before the update (11), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' </code></pre> <p>Here's my code in my mainViewcontroller</p> <pre><code>- (void)viewWillAppear:(BOOL)animated{ // Property List.plist code //Gets paths from root direcory. NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); //Get documents path. NSString *documentsPath = [paths objectAtIndex:0]; //Get the path to our PList file. plistPath = [documentsPath stringByAppendingPathComponent:@"Servers.plist"]; //Check to see if Property List.plist exists in documents. if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]){ [[NSFileManager defaultManager]copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"Servers" ofType:@"plist"] toPath:plistPath error:nil]; //If not in documents, get property list from main bundle. } arrayA = [[NSMutableArray alloc] initWithContentsOfFile:plistPath]; NSLog(@"%@\n%@", arrayA, [arrayA valueForKey:@"Hostname"]); tableData = [arrayA valueForKey:@"Hostname"]; [super viewWillAppear:animated]; [self.tableView reloadData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [tableData count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"showServerAction"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [tableView beginUpdates]; [arrayA writeToFile:plistPath atomically: TRUE]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView endUpdates]; } } </code></pre> <p><strong>UPDATE</strong> here's how my plist looks. it's a NSMutableArray <img src="https://i.stack.imgur.com/mlK55.png" alt="plist"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload