Skip to content

Commit

Permalink
Added property to store last selected indexPath in PSTableViewControl…
Browse files Browse the repository at this point in the history
…ler so that it can be deselected in viewDidAppear
  • Loading branch information
myell0w committed Mar 7, 2011
1 parent 47f3bda commit bd54b3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions TableView/PSTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
BOOL useShadows;
UITableView *tableView;
UITableViewStyle _tableViewStyle;
NSIndexPath *lastSelectedIndexPath_;
}

@property (nonatomic, retain) UITableView *tableView;
Expand Down
12 changes: 10 additions & 2 deletions TableView/PSTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
#import "ShadowedTableView.h"

@interface PSTableViewController ()

@property (nonatomic, retain) NSIndexPath *lastSelectedIndexPath;

@end

// http://cocoawithlove.com/2009/03/recreating-uitableviewcontroller-to.html
@implementation PSTableViewController

@synthesize tableViewStyle = _tableViewStyle, useShadows;
@synthesize tableViewStyle = _tableViewStyle;
@synthesize useShadows;
@synthesize lastSelectedIndexPath = lastSelectedIndexPath_;

///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
Expand All @@ -38,6 +43,7 @@ - (void)dealloc {
[tableView setDelegate:nil];
[tableView setDataSource:nil];
MCRelease(tableView);
MCRelease(lastSelectedIndexPath_);

[super dealloc];
}
Expand Down Expand Up @@ -78,13 +84,15 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[self.tableView reloadData];
// how to deselect?
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[self.tableView flashScrollIndicators];
// you have to set self.lastSelectedIndexPath in
// - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[self.tableView deselectRowAtIndexPath:self.lastSelectedIndexPath animated:YES];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit bd54b3d

Please sign in to comment.