Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- [self.usersTable beginUpdates];
- UITableViewCell *cell = (UITableViewCell *)[self.usersTable cellForRowAtIndexPath:indexPath];
- NSString *userNameToDelete = cell.textLabel.text;
- // Data source
- [self.appDict removeObjectForKey:userNameToDelete];
- self.arrayOfUserNames = [[NSMutableArray alloc] initWithArray:[self.appDict allKeys]];
- [self.appDict writeToFile:self.pathOfAppFile atomically:YES];
- // Deleting cell
- [self.usersTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- [self.usersTable endUpdates];
- }
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == [self.arrayOfUserNames count]) {
- return NO;
- }
- else {
- return YES;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.arrayOfUserNames count] + 1;
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- //delete your user record
- }
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- NSString *userNameToDelete = [[self arrayOfUserNames] objectAtIndex:indexPath.row];
- // Data source
- [self.appDict removeObjectForKey:userNameToDelete];
- self.arrayOfUserNames = [[NSMutableArray alloc] initWithArray:[self.appDict allKeys]];
- [self.appDict writeToFile:self.pathOfAppFile atomically:YES];
- [tableView reloadData];
- }
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement