diff --git a/Classes/PullRefreshTableViewController.m b/Classes/PullRefreshTableViewController.m index b373376..1d130d5 100644 --- a/Classes/PullRefreshTableViewController.m +++ b/Classes/PullRefreshTableViewController.m @@ -37,16 +37,38 @@ @implementation PullRefreshTableViewController @synthesize textPull, textRelease, textLoading, refreshHeaderView, refreshLabel, refreshArrow, refreshSpinner; -- (id)initWithStyle:(UITableViewStyle)style { - self = [super initWithStyle:style]; +- (void)initTextLabels { if (self != nil) { textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."]; textRelease = [[NSString alloc] initWithString:@"Release to refresh..."]; textLoading = [[NSString alloc] initWithString:@"Loading..."]; } +} + +- (id)init { + self = [super init]; + [self initTextLabels]; return self; } +- (id)initWithStyle:(UITableViewStyle)style { + self = [super initWithStyle:style]; + [self initTextLabels]; + return self; +} + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + [self initTextLabels]; + return self; +} + +- (id)initWithCoder:(NSCoder *)aDecoder { + self = [super initWithCoder:aDecoder]; + [self initTextLabels]; + return self; +} + - (void)viewDidLoad { [super viewDidLoad]; [self addPullToRefreshHeader]; @@ -55,21 +77,21 @@ - (void)viewDidLoad { - (void)addPullToRefreshHeader { refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)]; refreshHeaderView.backgroundColor = [UIColor clearColor]; - + refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, REFRESH_HEADER_HEIGHT)]; refreshLabel.backgroundColor = [UIColor clearColor]; refreshLabel.font = [UIFont boldSystemFontOfSize:12.0]; refreshLabel.textAlignment = UITextAlignmentCenter; - + refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]]; refreshArrow.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 27) / 2, (REFRESH_HEADER_HEIGHT - 44) / 2, 27, 44); - + refreshSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; refreshSpinner.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 20) / 2, (REFRESH_HEADER_HEIGHT - 20) / 2, 20, 20); refreshSpinner.hidesWhenStopped = YES; - + [refreshHeaderView addSubview:refreshLabel]; [refreshHeaderView addSubview:refreshArrow]; [refreshHeaderView addSubview:refreshSpinner]; @@ -114,7 +136,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL - (void)startLoading { isLoading = YES; - + // Show the header [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; @@ -123,14 +145,14 @@ - (void)startLoading { refreshArrow.hidden = YES; [refreshSpinner startAnimating]; [UIView commitAnimations]; - + // Refresh action! [self refresh]; } - (void)stopLoading { isLoading = NO; - + // Hide the header [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self];