Permalink
Browse files

Fixing loading indicator.

  • Loading branch information...
1 parent 2dc1231 commit 9fbc15ef73aa7b16a8870f3300fc6509270374a1 @jsakuda jsakuda committed Jul 18, 2012
Showing with 30 additions and 53 deletions.
  1. +7 −2 HI Capacity/CalendarViewController.m
  2. +3 −1 HI Capacity/PostsViewController.h
  3. +20 −50 HI Capacity/PostsViewController.m
@@ -38,7 +38,7 @@ - (void)viewDidLoad{
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"noise"]];
}
-- (void)viewWillAppear:(BOOL)animated {
+- (void)viewDidAppear:(BOOL)animated {
// Deselect any selected table row there may be
[[super tableView] deselectRowAtIndexPath:[[super tableView] indexPathForSelectedRow] animated:animated];
[super viewWillAppear:animated];
@@ -49,12 +49,17 @@ - (void)viewWillAppear:(BOOL)animated {
}
}
-- (void)viewDidDisappear:(BOOL)animated {
+- (void)viewWillDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// Hide the loading box?
[self dismissLoading:NO];
}
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return UIInterfaceOrientationIsPortrait(interfaceOrientation);
+}
+
- (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NSDate*)startDate toDate:(NSDate*)lastDate {
if ([lastStartDate isSameDay:startDate] && [lastEndDate isSameDay:lastDate]) {
// Do not query again. The query dates match. This happens if the table is manually reloaded.
@@ -8,7 +8,9 @@
#import <UIKit/UIKit.h>
-@interface PostsViewController : UITableViewController<UITableViewDelegate>
+@interface PostsViewController : UITableViewController<UITableViewDelegate> {
+ MKNetworkOperation *runningOp;
+}
@property (strong, nonatomic) NSMutableArray *posts;
@property (weak, nonatomic) IBOutlet UITableView *postTableView;
@@ -47,14 +47,16 @@ - (void)viewDidLoad
[headerFields setValue:@"iOS" forKey:@"x-client-identifier"];
[headerFields setValue:@"application/json" forKey:@"Accept"];
HTTPEngine *httpEngine = [[HTTPEngine alloc] initWithHostName:@"hicapacity.org" customHeaderFields:headerFields];
- [httpEngine posts:nil :^(NSMutableArray *returnedPosts) {
+ runningOp = [httpEngine posts:nil :^(NSMutableArray *returnedPosts) {
posts = returnedPosts;
[postTableView reloadData];
[self dismissLoading:NO]; // Stop loading spinner
+ runningOp = nil;
}
onError:^(NSError *error) {
// please handle the error
[self dismissLoading:YES]; // Stop loading spinner
+ runningOp = nil;
}];
}
@@ -67,9 +69,24 @@ - (void)viewDidUnload
// e.g. self.myOutlet = nil;
}
+- (void)viewDidAppear:(BOOL)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)viewWillDisappear:(BOOL)animated {
+ [super viewDidDisappear:animated];
+ // Hide the loading box?
+ [self dismissLoading:NO];
+}
+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
+ return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
#pragma mark - Table view data source
@@ -101,45 +118,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
-/*
- // Override to support conditional editing of the table view.
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Return NO if you do not want the specified item to be editable.
- return YES;
- }
- */
-
-/*
- // Override to support editing the table view.
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- // Delete the row from the data source
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
- else if (editingStyle == UITableViewCellEditingStyleInsert) {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
- }
- */
-
-/*
- // Override to support rearranging the table view.
- - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
- {
- }
- */
-
-/*
- // Override to support conditional rearranging of the table view.
- - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Return NO if you do not want the item to be re-orderable.
- return YES;
- }
- */
-
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"PushPost"])
@@ -153,15 +131,7 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
- // Navigation logic may go here. Create and push another view controller.
- /*
- <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
- // ...
- // Pass the selected object to the new view controller.
- [self.navigationController pushViewController:detailViewController animated:YES];
- */
- // PostContentViewController *postContentViewController = [[PostContentViewController alloc] initWithNibName:nil bundle:nil];
- // postContentViewController setPost:<#(NSDictionary *)#>
+
}
- (void) showLoading {

0 comments on commit 9fbc15e

Please sign in to comment.