####iOS7 Programming Cookbook 第四章 Deleting Cells and Sections from TableViews
#####ViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
static NSString *CellIdentifier = @"Cell";
@interface ()
@property (nonatomic, strong) NSMutableArray *allTimes;
@property (nonatomic, strong) UIRefreshControl *refreshControl; @end
@implementation
-(void)viewDidLoad{ [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; }
- (void) handleRefresh:(id)paramSender{ int64_t delayInSeconds = 1.0f; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.allTimes addObject:[NSDate date]]; [self.refreshControl endRefreshing]; NSIndexPath *indexPathOfNewRow = [NSIndexPath indexPathForRow:self.allTimes.count-1 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPathOfNewRow] withRowAnimation:UITableViewRowAnimationAutomatic]; }); }
- (id)initWithStyle:(UITableViewStyle)style{ self = [super initWithStyle:style]; if (self) { [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier]; self.allTimes = [NSMutableArray arrayWithObject:[NSDate date]]; self.refreshControl = [[UIRefreshControl alloc] init]; self.refreshControl = self.refreshControl; [self.refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged]; } return self; }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.allTimes.count; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.textLabel.text = [NSString stringWithFormat:@"%@",self.allTimes[indexPath.row]]; return cell; }
@end
|
Reference
近期评论