// // TasksViewController.m // TumblrDownloader // // Created by HonorLee on 16/1/17. // Copyright © 2016年 HonorLee. All rights reserved. // #import "TasksViewController.h" @interface TasksViewController () @property NSUserDefaults *userDefaults; @property UIRefreshControl *uirefresh; @property NSMutableArray *TaskData; @end @implementation TasksViewController //UIRefreshControl *uirefresh; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _TaskTableView.delegate = self; _TaskTableView.dataSource = self; _uirefresh = [[UIRefreshControl alloc]init]; _uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefresh", nil)]; [_TaskTableView addSubview:_uirefresh]; [_uirefresh addTarget:self action:@selector(pullToRefresh) forControlEvents:UIControlEventValueChanged]; _userDefaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.honorlee.TumblrDownloader"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)viewDidAppear:(BOOL)animated{ [self pullToRefresh]; } #pragma Table Refresh -(void)pullToRefresh{ NSLog(@"Start refresh"); _uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefreshing", nil)]; [self reloadCellData]; [self refreshEnd]; } -(void)refreshEnd{ [_uirefresh endRefreshing]; _uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefreshEnd", nil)]; } -(void)reloadCellData{ [_userDefaults synchronize]; _TaskData = [NSMutableArray arrayWithArray:(NSMutableArray *)[_userDefaults objectForKey:@"tasks"]]; [_TaskTableView reloadData]; NSLog(@"Data loaded"); } #pragma TableViewDelegate -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [_TaskTableView dequeueReusableCellWithIdentifier:@"TaskCellStyle"]; // cell.textLabel. cell.textLabel.text = _TaskData[indexPath.row]; return cell; } //-tabl -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_TaskData count]; } -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ return 1; } @end