TasksViewController.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // TasksViewController.m
  3. // TumblrDownloader
  4. //
  5. // Created by HonorLee on 16/1/17.
  6. // Copyright © 2016年 HonorLee. All rights reserved.
  7. //
  8. #import "TasksViewController.h"
  9. @interface TasksViewController ()
  10. @property NSUserDefaults *userDefaults;
  11. @property UIRefreshControl *uirefresh;
  12. @property NSMutableArray *TaskData;
  13. @end
  14. @implementation TasksViewController
  15. //UIRefreshControl *uirefresh;
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. _TaskTableView.delegate = self;
  20. _TaskTableView.dataSource = self;
  21. _uirefresh = [[UIRefreshControl alloc]init];
  22. _uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefresh", nil)];
  23. [_TaskTableView addSubview:_uirefresh];
  24. [_uirefresh addTarget:self action:@selector(pullToRefresh) forControlEvents:UIControlEventValueChanged];
  25. _userDefaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.honorlee.TumblrDownloader"];
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. // Dispose of any resources that can be recreated.
  30. }
  31. -(void)viewDidAppear:(BOOL)animated{
  32. [self pullToRefresh];
  33. }
  34. #pragma Table Refresh
  35. -(void)pullToRefresh{
  36. NSLog(@"Start refresh");
  37. _uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefreshing", nil)];
  38. [self reloadCellData];
  39. [self refreshEnd];
  40. }
  41. -(void)refreshEnd{
  42. [_uirefresh endRefreshing];
  43. _uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefreshEnd", nil)];
  44. }
  45. -(void)reloadCellData{
  46. [_userDefaults synchronize];
  47. _TaskData = [NSMutableArray arrayWithArray:(NSMutableArray *)[_userDefaults objectForKey:@"tasks"]];
  48. [_TaskTableView reloadData];
  49. NSLog(@"Data loaded");
  50. }
  51. #pragma TableViewDelegate
  52. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  53. UITableViewCell *cell = [_TaskTableView dequeueReusableCellWithIdentifier:@"TaskCellStyle"];
  54. // cell.textLabel.
  55. cell.textLabel.text = _TaskData[indexPath.row];
  56. return cell;
  57. }
  58. //-tabl
  59. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  60. return [_TaskData count];
  61. }
  62. -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
  63. return 1;
  64. }
  65. @end