iOS - UITableView' UIRefreshControl与UITableViewController的UIRefreshControl

时间:2016-05-13 19:24:11

标签: ios objective-c uitableview uirefreshcontrol

在我的UIViewController中,我有UITableView作为其中一个子视图。我使用以下代码添加UIRefreshControl

// enable "pull to refresh"
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull To Refresh!" attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : [UIFont systemFontOfSize:17]}];
[refreshControl addTarget:self action:@selector(fetchArticles) forControlEvents:UIControlEventValueChanged];
refreshControl.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green:102.0f/255.0f blue:153.0f/255.0f alpha:1.0];
refreshControl.tintColor = [UIColor whiteColor];
self.refreshControl = refreshControl;
[self.tableView addSubview:self.refreshControl];

我的应用中有另一个使用UITableViewController的屏幕,其UIRefreshControl与我为UITableView添加的屏幕更加不同。

拖动时单独UIRefreshControl的{​​{1}}速度较慢,我通常只需拖动FARTHER即可让它开始刷新。

我的另一个屏幕上的UITableView的{​​{1}}在拖动时速度更快,而且我不必拖动到目前为止让它开始刷新。

我更喜欢UIRefreshControl UITableViewController的更顺畅的行为,因此我如何让UITableViewControllerUIRefreshControl的行为更像默认一个属于UIRefreshControl

这可能吗?或者使用UITableView并使用UITableViewController我唯一的选择?

1 个答案:

答案 0 :(得分:1)

UIRefreshControl旨在与UITableViewController合作;在Apple的网站上说:

  

由于刷新控件专门设计用于由表视图控制器管理的表视图,因此在不同的上下文中使用它可能会导致未定义的行为。

话虽如此,人们在没有UITableViewControllerUIRefreshControl without UITableViewController的情况下取得了成功。使用风险自负。