Skip to content
Browse files

Hiding loading spinner when leaving tab.

  • Loading branch information...
1 parent bfee380 commit 89358d9260217e83544f3268373cb162dd0a4675 @jsakuda jsakuda committed Jun 7, 2012
Showing with 10 additions and 2 deletions.
  1. +1 −0 HI Capacity/CalendarViewController.h
  2. +9 −2 HI Capacity/CalendarViewController.m
View
1 HI Capacity/CalendarViewController.h
@@ -12,6 +12,7 @@
@interface CalendarViewController : TKCalendarMonthTableViewController {
NSDate *lastStartDate;
NSDate *lastEndDate;
+ MKNetworkOperation *runningOp;
}
@property (retain,nonatomic) NSMutableArray *dataArray;
View
11 HI Capacity/CalendarViewController.m
@@ -37,12 +37,17 @@ - (void)viewWillAppear:(BOOL)animated {
// Deselect any selected table row there may be
[[super tableView] deselectRowAtIndexPath:[[super tableView] indexPathForSelectedRow] animated:animated];
[super viewWillAppear:animated];
+
+ // Check if operation is still running, if it is show the loading box again
+ if (runningOp != nil && [runningOp isExecuting]) {
+ [self showLoading];
+ }
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// Hide the loading box?
- [SVProgressHUD dismiss];
+ [self dismissLoading:NO];
}
- (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NSDate*)startDate toDate:(NSDate*)lastDate {
@@ -65,7 +70,7 @@ - (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NS
[headerFields setValue:@"iOS" forKey:@"x-client-identifier"];
[headerFields setValue:@"application/json" forKey:@"Accept"];
HTTPEngine *httpEngine = [[HTTPEngine alloc] initWithHostName:@"www.googleapis.com" customHeaderFields:headerFields];
- [httpEngine eventsFrom:startDate to:lastDate onCompletion:^(NSMutableArray *returnedEvents) {
+ runningOp = [httpEngine eventsFrom:startDate to:lastDate onCompletion:^(NSMutableArray *returnedEvents) {
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
@@ -107,10 +112,12 @@ - (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NS
[[self monthView] reload]; // reload the month view since new events were loaded
[self dismissLoading:NO];
+ runningOp = nil;
}
onError:^(NSError *error) {
NSLog(@"%@", error);
[self dismissLoading:YES];
+ runningOp = nil;
}]; // end of completion block
return dataArray;
}

0 comments on commit 89358d9

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