summaryrefslogtreecommitdiff
path: root/Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-07-14 15:17:39 -0600
committermo khan <mo@mokhan.ca>2013-07-14 15:17:39 -0600
commit6ff632a1444a214ba61597ae9e1a034e5f1f6073 (patch)
treef11725593b3fcb7d266e16d76b57755cd3e39af1 /Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m
parentb4051750b51ad5b9ee0574fa5ceaa71649c19e95 (diff)
add more pods
Diffstat (limited to 'Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m')
-rw-r--r--Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m88
1 files changed, 88 insertions, 0 deletions
diff --git a/Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m b/Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m
new file mode 100644
index 0000000..3cca651
--- /dev/null
+++ b/Pods/SVPullToRefresh/Demo/SVPullToRefreshDemo/SVViewController.m
@@ -0,0 +1,88 @@
+//
+// SVViewController.m
+// SVPullToRefreshDemo
+//
+// Created by Sam Vermette on 23.04.12.
+// Copyright (c) 2012 Home. All rights reserved.
+//
+
+#import "SVViewController.h"
+#import "SVPullToRefresh.h"
+
+@interface SVViewController () <UITableViewDelegate, UITableViewDataSource>
+
+@property (nonatomic, strong) NSMutableArray *dataSource;
+
+@end
+
+@implementation SVViewController
+@synthesize tableView = tableView;
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ self.dataSource = [NSMutableArray array];
+
+ for(int i=0; i<15; i++)
+ [self.dataSource addObject:[NSDate dateWithTimeIntervalSinceNow:-(i*90)]];
+
+ __weak SVViewController *weakSelf = self;
+
+ // setup pull-to-refresh
+ [self.tableView addPullToRefreshWithActionHandler:^{
+
+ int64_t delayInSeconds = 2.0;
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+ [weakSelf.tableView beginUpdates];
+ [weakSelf.dataSource insertObject:[NSDate date] atIndex:0];
+ [weakSelf.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
+ [weakSelf.tableView endUpdates];
+
+ [weakSelf.tableView.pullToRefreshView stopAnimating];
+ });
+ }];
+
+ // setup infinite scrolling
+ [self.tableView addInfiniteScrollingWithActionHandler:^{
+
+ int64_t delayInSeconds = 2.0;
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+ [weakSelf.tableView beginUpdates];
+ [weakSelf.dataSource addObject:[weakSelf.dataSource.lastObject dateByAddingTimeInterval:-90]];
+ [weakSelf.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:weakSelf.dataSource.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
+ [weakSelf.tableView endUpdates];
+
+ [weakSelf.tableView.infiniteScrollingView stopAnimating];
+ });
+ }];
+
+ // trigger the refresh manually at the end of viewDidLoad
+ [tableView triggerPullToRefresh];
+}
+
+#pragma mark -
+#pragma mark UITableViewDataSource
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return self.dataSource.count;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ static NSString *identifier = @"Cell";
+ UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier];
+
+ if (cell == nil)
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
+
+ NSDate *date = [self.dataSource objectAtIndex:indexPath.row];
+ cell.textLabel.text = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterMediumStyle];
+ return cell;
+}
+
+@end