deselect table view cells in viewWillAppear

This commit is contained in:
Sami Samhuri 2012-03-24 11:00:22 -07:00
parent 22f6126f66
commit 7e935d569a
2 changed files with 11 additions and 5 deletions

View file

@ -19,6 +19,7 @@
@property (nonatomic, retain) NSString *currentEpisodeNumber; @property (nonatomic, retain) NSString *currentEpisodeNumber;
@property (nonatomic, retain) NSString *currentEpisodeName; @property (nonatomic, retain) NSString *currentEpisodeName;
@property (nonatomic, retain) NSTimer *checkNowPlayingTimer; @property (nonatomic, retain) NSTimer *checkNowPlayingTimer;
@property (nonatomic, retain) UITableViewCell *selectedCell;
- (void) checkNowPlaying; - (void) checkNowPlaying;

View file

@ -20,6 +20,7 @@
@synthesize currentEpisodeNumber = _currentEpisodeNumber; @synthesize currentEpisodeNumber = _currentEpisodeNumber;
@synthesize currentEpisodeName = _currentEpisodeName; @synthesize currentEpisodeName = _currentEpisodeName;
@synthesize checkNowPlayingTimer = _checkNowPlayingTimer; @synthesize checkNowPlayingTimer = _checkNowPlayingTimer;
@synthesize selectedCell = _selectedCell;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{ {
@ -44,10 +45,11 @@
{ {
[super viewWillAppear: animated]; [super viewWillAppear: animated];
for (int i = 0; i < [self tableView: self.tableView numberOfRowsInSection: 0]; ++i) { UITableViewCell *cell = self.selectedCell;
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: i inSection: 0]]; if (animated && cell) {
cell.accessoryView = nil; cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[self.tableView deselectRowAtIndexPath: [self.tableView indexPathForSelectedRow] animated: YES];
} }
self.checkNowPlayingTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 self.checkNowPlayingTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0
@ -140,9 +142,9 @@
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) { if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.adjustsFontSizeToFitWidth = YES;
}
if (self.currentShow && indexPath.section == 0) { if (self.currentShow && indexPath.section == 0) {
self.currentShow.delegate = self; self.currentShow.delegate = self;
@ -177,12 +179,15 @@
[[self.fiveByFive.shows objectAtIndex: indexPath.row] getEpisodes]; [[self.fiveByFive.shows objectAtIndex: indexPath.row] getEpisodes];
UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite]; UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite];
[indicatorView startAnimating]; [indicatorView startAnimating];
[tableView cellForRowAtIndexPath: indexPath].accessoryView = indicatorView; self.selectedCell = [tableView cellForRowAtIndexPath: indexPath];
self.selectedCell.accessoryView = indicatorView;
} }
} }
- (void) gotEpisodesForShow: (Show *)show - (void) gotEpisodesForShow: (Show *)show
{ {
self.selectedCell.accessoryView = nil;
self.selectedCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.selectedCell.detailTextLabel.text = [[[[show episodes] objectAtIndex: 0] date] relativeToNow]; self.selectedCell.detailTextLabel.text = [[[[show episodes] objectAtIndex: 0] date] relativeToNow];
self.showViewController.show = show; self.showViewController.show = show;
[self.navigationController pushViewController: self.showViewController animated: YES]; [self.navigationController pushViewController: self.showViewController animated: YES];