1

У меня есть табличное представление с ячейками прототипа.Pulltorefresh работает только один раз не раз

У меня следующий код в моем методе viewDidLoad,

_refreshControl = [[UIRefreshControl alloc]init]; 

[_refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; 
UITableViewController *tableViewController = [[UITableViewController alloc] init]; 
tableViewController.tableView = _tblView; 
tableViewController.refreshControl = _refreshControl; 

Ниже мой метод RefreshData ....

-(void)refreshData 
{ 
    [_request getApproveStatutoryMapping]; 
    UITableViewController *tableViewController = [[UITableViewController alloc] init]; 
tableViewController.tableView = _tblView; 
[_tblView reloadData]; 

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
[formatter setDateFormat:@"MMM d, h:mm a"]; 
NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]]; 
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor] 
                  forKey:NSForegroundColorAttributeName]; 
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary]; 
tableViewController.refreshControl.attributedTitle = attributedTitle; 

[tableViewController.refreshControl endRefreshing]; 

}

Проблема заключается в том, что

  1. отнесенныйТитайм не является visi ble
  2. Вытягивание для обновления работает только один раз, и если я вытащу его снова, это не сработает. Почему это так?

ответ

1

Вы определите UITableViewController *tableViewController как свойство вашего UIViewController

В методе refreshData удалить строки

UITableViewController *tableViewController = [[UITableViewController alloc] init]; 
tableViewController.tableView = _tblView; 

Метод endRefreshing должен вызываться после того, как ваши обновления данных, а не когда вы начинаете обновить его, или вы увидите предзагрузчик менее секунды, не дожидаясь обновлений

Здесь

NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor] 
                  forKey:NSForegroundColorAttributeName]; 

Вы определяете цвет вашего заголовка обновления, как белый, если фон белый, вы никогда не увидите название