diff --git a/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.m b/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.m index 4af2eda7..1a0ca61e 100644 --- a/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.m +++ b/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.m @@ -46,6 +46,9 @@ @interface LoggerMessageViewController () @property (nonatomic, retain) NSFetchedResultsController *messageFetchResultController; @property (nonatomic, retain) NSDictionary *clientInfo; +@property NSInteger currentRun; +@property NSInteger runCount; +@property uLong currentClientHash; -(void)readMessages:(NSNotification *)aNotification; -(void)insertTableViewSection; -(void)deleteTableViewSection; @@ -108,6 +111,9 @@ - (void)viewDidLoad self.toolBar.noiseBlendMode = kCGBlendModeMultiply; self.toolBar.noiseOpacity = 0.1; + self.currentRun = -1; + self.runCount = -1; + #ifdef TEST_SHOW [self readMessages:nil]; #endif @@ -160,30 +166,34 @@ -(void)readMessages:(NSNotification *)aNotification MTLog(@"userInfo %@",userInfo); - NSInteger runCount = [[userInfo objectForKey:kClientRunCount] integerValue]; + self.runCount = [[userInfo objectForKey:kClientRunCount] integerValue]; + self.currentRun = self.runCount; self.clientInfo = nil; self.clientInfo = userInfo; + self.currentClientHash = [[userInfo objectForKey:kClientHash] integerValue]; + #endif - self.runCountLabel.text = \ - [NSString stringWithFormat: - NSLocalizedString(@"Run %ld of %ld", nil),runCount+1,runCount+1]; + + [self enableRunControls]; + [self fetchDataForRun:self.currentRun + withClientHash:self.currentClientHash]; +} - self.previousRunButton.hidden = runCount < 0; - self.nextRunButton.hidden = YES; +- (void)enableRunControls +{ + self.runCountLabel.text = \ + [NSString stringWithFormat: + NSLocalizedString(@"Run %ld of %ld", nil),self.currentRun+1,self.runCount+1]; - [self fetchDataForRun:runCount+1 - notification:aNotification]; + self.previousRunButton.hidden = self.currentRun <= 0; + self.nextRunButton.hidden = self.currentRun >= self.runCount; } - (void)fetchDataForRun:(NSInteger)run - notification:(NSNotification *)aNotification + withClientHash:(uLong)clientHash { - NSDictionary *userInfo = [aNotification userInfo]; - - uLong clientHash = [[userInfo objectForKey:kClientHash] integerValue]; - assert([self.dataManager messageDisplayContext] != nil); if(_messageFetchResultController != nil) @@ -277,6 +287,27 @@ -(void)deleteTableViewSection deleteSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; } +//------------------------------------------------------------------------------ +#pragma mark Actions +//------------------------------------------------------------------------------ +- (IBAction)didPressPreviousButton:(id)sender { + if (self.currentRun > 0) { + self.currentRun--; + [self enableRunControls]; + [self fetchDataForRun:self.currentRun + withClientHash:self.currentClientHash]; + } +} + +- (IBAction)didPressNextButton:(id)sender { + if (self.currentRun < self.runCount) { + self.currentRun++; + [self enableRunControls]; + [self fetchDataForRun:self.currentRun + withClientHash:self.currentClientHash]; + } +} + //------------------------------------------------------------------------------ #pragma mark Timer Control //------------------------------------------------------------------------------ @@ -324,7 +355,8 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)aSection { - return [[self.messageFetchResultController fetchedObjects] count]; + NSArray *records = [self.messageFetchResultController fetchedObjects]; + return [records count]; } - (UITableViewCell *)tableView:(UITableView *)aTableView diff --git a/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.xib b/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.xib index c766c3b3..118cd483 100644 --- a/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.xib +++ b/iPad Viewer/ViewController/MessageViewController/LoggerMessageViewController.xib @@ -73,9 +73,9 @@