Skip to content
Browse files

refs #12 - maintain list selection after enter/leave edit mode

Still need to handle what happens on swipe-to-delete
  • Loading branch information...
1 parent 6395eb6 commit 672d1e9b3462cd3ef07cc47dbc7e5ee77786f70c @cdzombak committed Mar 7, 2013
Showing with 26 additions and 0 deletions.
  1. +26 −0 buyvmmanager/BVMServersListViewController.m
View
26 buyvmmanager/BVMServersListViewController.m
@@ -32,6 +32,8 @@ @interface BVMServersListViewController () <UIPopoverControllerDelegate>
@property (nonatomic, strong, readonly) UIToolbar *bottomToolbar;
+@property (nonatomic, strong) NSString *serverIdSelectedBeforeEdit;
+
@end
@implementation BVMServersListViewController
@@ -89,12 +91,21 @@ -(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];
+ }
+
[super setEditing:editing animated:animated];
if (editing) {
self.navigationItem.leftBarButtonItem = self.addItem;
} else {
self.navigationItem.leftBarButtonItem = nil;
+
+ NSIndexPath *ipToSelect = [self indexPathForServerId:self.serverIdSelectedBeforeEdit];
+ [self.tableView selectRowAtIndexPath:ipToSelect animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
}
@@ -238,6 +249,21 @@ - (NSString *)serverNameForIndexPath:(NSIndexPath *)indexPath
return self.servers[serverId];
}
+- (NSIndexPath *)indexPathForServerId:(NSString *)serverId
+{
+ if (serverId == nil) return nil;
+
+ NSUInteger idIndex = [self.orderedServerIds indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
+ if ([serverId isEqualToString:obj]) {
+ stop = YES;
+ return YES;
+ }
+ return NO;
+ }];
+
+ return [NSIndexPath indexPathForItem:idIndex inSection:0];
+}
+
#pragma mark UIPopoverControllerDelegate methods
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController

0 comments on commit 672d1e9

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