views:

28

answers:

1

Hi all,

I have a plist file that is brought into a tableview, and now want to remove items that I have added in the past, but don't even know where to start. I have got the editing working, well it shows on each line, any help more than welcome on this!

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return amounts.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //Create Cell
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

    //Fill cell
    NSDictionary *budgetItem = [amounts objectAtIndex:indexPath.row];
    currentNumber = [[budgetItem objectForKey:@"Value"] floatValue];

    NSString *imageFile = [[NSBundle mainBundle] pathForResource:@"mini" ofType:@"png"];
    UIImage *ui = [[UIImage alloc] initWithContentsOfFile:imageFile];
    cell.imageView.image = ui;
    result = result + currentNumber;


    cell.textLabel.text = [NSString stringWithFormat:@"£%.2f",currentNumber];
    NSString *detailTxt = [NSString stringWithFormat:@"%@ - %@", [budgetItem objectForKey:@"Description"], [budgetItem objectForKey:@"Date"]];
    cell.detailTextLabel.text = detailTxt;

    //Return it
    return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}


- (void) loadData{

    //Get file location
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"saveBudget.plist"];

    // Load items
    NSString *error;
    NSPropertyListFormat format;
    NSData *plistData = [NSData dataWithContentsOfFile:path];
    NSArray *amountData = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];

    // Add Edit Button
    self.navigationItem.rightBarButtonItem = self.editButtonItem;

}

- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing: editing animated: animated];
    [dataTable setEditing:editing animated:animated];
}
+1  A: 

You read data from you file into a mutable container (an array most likely). Then you make changes to the container in response to user actions using the methods that are provided through UITableView. Next, write the container back out again to disk.

Johan Kool