Skip to content
Browse files

closes #12 - restore selection after a row edit

  • Loading branch information...
1 parent 672d1e9 commit 1702cdeb0a44bea167f6be10dca8b19958683c4d @cdzombak committed Mar 7, 2013
Showing with 32 additions and 6 deletions.
  1. +32 −6 buyvmmanager/BVMServersListViewController.m
View
38 buyvmmanager/BVMServersListViewController.m
@@ -92,9 +92,7 @@ -(void)viewDidAppear:(BOOL)animated
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if (editing) {
- NSIndexPath *selectedIP = [self.tableView indexPathForSelectedRow];
- if (selectedIP == nil) self.serverIdSelectedBeforeEdit = nil;
- else self.serverIdSelectedBeforeEdit = [self serverIdForIndexPath:selectedIP];
+ [self saveSelection];
}
[super setEditing:editing animated:animated];
@@ -103,9 +101,7 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated
self.navigationItem.leftBarButtonItem = self.addItem;
} else {
self.navigationItem.leftBarButtonItem = nil;
-
- NSIndexPath *ipToSelect = [self indexPathForServerId:self.serverIdSelectedBeforeEdit];
- [self.tableView selectRowAtIndexPath:ipToSelect animated:YES scrollPosition:UITableViewScrollPositionMiddle];
+ [self restoreSelection];
}
}
@@ -182,6 +178,21 @@ - (void)displayEditorForIndexPath:(NSIndexPath *)indexPath
}
}
+#pragma mark Selection save/restore
+
+- (void)saveSelection
+{
+ NSIndexPath *selectedIP = [self.tableView indexPathForSelectedRow];
+ if (selectedIP == nil) self.serverIdSelectedBeforeEdit = nil;
+ else self.serverIdSelectedBeforeEdit = [self serverIdForIndexPath:selectedIP];
+}
+
+- (void)restoreSelection
+{
+ NSIndexPath *ipToSelect = [self indexPathForServerId:self.serverIdSelectedBeforeEdit];
+ [self.tableView selectRowAtIndexPath:ipToSelect animated:YES scrollPosition:UITableViewScrollPositionMiddle];
+}
+
#pragma mark Data
- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
@@ -340,6 +351,21 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}
+- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ [self saveSelection];
+}
+
+- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ [self restoreSelection];
+}
+
+- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return NSLocalizedString(@"Forget", nil);
+}
+
#pragma mark Property Overrides
- (void)setServers:(NSDictionary *)servers

0 comments on commit 1702cde

Please sign in to comment.
Something went wrong with that request. Please try again.