Permalink
Browse files

Add SVProgressHUD

  • Loading branch information...
winfield committed Jun 7, 2012
1 parent 01e7404 commit d224c8ded94441d4ec5f90a9ea34f261aece219e
@@ -8,6 +8,7 @@
#import "RCITopicDetailViewController.h"
#import "AFNetworking.h"
+#import "SVProgressHUD.h"
NSString *const RCITopicBaseUrlString = @"http://ruby-china.org/api/topics/";
@@ -27,6 +28,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];
+ [SVProgressHUD showWithStatus:@"Loading..."];
[self performTopicDetailRequest];
}
@@ -58,7 +60,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- //return [[self topicReplies] count] + 1;
return [[self.topicDetail objectForKey:@"replies"] count] + 1;
}
@@ -80,13 +81,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UILabel *bodyLabel = (UILabel *)[topicDetailCell viewWithTag:105];
NSString *bodyString = [self.topicDetail objectForKey:@"body"];
CGSize expectedLabelSize = [self labelSize:@"Topic Detail" withLabelTag:105 withBodyString:bodyString];
- NSLog(@"Body label size: %f", expectedLabelSize.height);
//adjust the label the the new height.
CGRect newFrame = bodyLabel.frame;
newFrame.size.height = expectedLabelSize.height + 90.0f;
bodyLabel.frame = newFrame;
bodyLabel.text = bodyString;
- NSLog(@"%@", bodyString);
UIImageView *imageView = (UIImageView *)[topicDetailCell viewWithTag:106];
NSURL *gravatarUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://gravatar.com/avatar/%@.png?s=40", [[self.topicDetail objectForKey:@"user"] objectForKey:@"gravatar_hash"]]];
@@ -130,7 +129,6 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
NSString *titleString = [self.topicDetail objectForKey:@"title"];
CGSize titleLabelSize = [self labelSize:@"Topic Detail" withLabelTag:101 withBodyString:titleString];
CGSize bodyLabelSize = [self labelSize:@"Topic Detail" withLabelTag:105 withBodyString:bodyString];
- NSLog(@"Header size: %f", titleLabelSize.height + bodyLabelSize.height);
return titleLabelSize.height + bodyLabelSize.height + 160.0f;
} else {
NSString *bodyString = [[self.topicReplies objectAtIndex:(indexPath.row-1)] objectForKey:@"body"];
@@ -162,13 +160,13 @@ - (void)performTopicDetailRequest
{
NSString *detailUrl = [RCITopicBaseUrlString stringByAppendingFormat:@"%@.json", self.topicId];
NSURL *url = [NSURL URLWithString:detailUrl];
- NSLog(@"URL: %@", url);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.topicDetail = [JSON copy];
[self.topicTableView reloadData];
[self stopLoading];
+ [SVProgressHUD dismiss];
} failure:nil];
@@ -10,6 +10,7 @@
#import "RCITopicsViewController.h"
#import "RCITopicDetailViewController.h"
#import "AFNetworking.h"
+#import "SVProgressHUD.h"
NSString *const RCITopicsUrlString = @"http://ruby-china.org/api/topics.json";
@@ -26,6 +27,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];
+ [SVProgressHUD showWithStatus:@"Loading..."];
[self performTopicsRequest];
}
@@ -104,6 +106,7 @@ - (void)performTopicsRequest
self.topics = [JSON copy];
[self.topicTableView reloadData];
[self stopLoading];
+ [SVProgressHUD dismiss];
} failure:nil];
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,44 @@
+//
+// SVProgressHUD.h
+//
+// Created by Sam Vermette on 27.03.11.
+// Copyright 2011 Sam Vermette. All rights reserved.
+//
+// https://github.com/samvermette/SVProgressHUD
+//
+
+#import <UIKit/UIKit.h>
+#import <AvailabilityMacros.h>
+
+enum {
+ SVProgressHUDMaskTypeNone = 1, // allow user interactions while HUD is displayed
+ SVProgressHUDMaskTypeClear, // don't allow
+ SVProgressHUDMaskTypeBlack, // don't allow and dim the UI in the back of the HUD
+ SVProgressHUDMaskTypeGradient // don't allow and dim the UI with a a-la-alert-view bg gradient
+};
+
+typedef NSUInteger SVProgressHUDMaskType;
+
+@interface SVProgressHUD : UIView
+
++ (void)show;
++ (void)showWithStatus:(NSString*)status;
++ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
++ (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
+
++ (void)showSuccessWithStatus:(NSString*)string;
++ (void)showSuccessWithStatus:(NSString *)string duration:(NSTimeInterval)duration;
++ (void)showErrorWithStatus:(NSString *)string;
++ (void)showErrorWithStatus:(NSString *)string duration:(NSTimeInterval)duration;
+
++ (void)setStatus:(NSString*)string; // change the HUD loading status while it's showing
+
++ (void)dismiss; // simply dismiss the HUD with a fade+scale out animation
++ (void)dismissWithSuccess:(NSString*)successString; // also displays the success icon image
++ (void)dismissWithSuccess:(NSString*)successString afterDelay:(NSTimeInterval)seconds;
++ (void)dismissWithError:(NSString*)errorString; // also displays the error icon image
++ (void)dismissWithError:(NSString*)errorString afterDelay:(NSTimeInterval)seconds;
+
++ (BOOL)isVisible;
+
+@end
Oops, something went wrong.

0 comments on commit d224c8d

Please sign in to comment.