2016-05-13 69 views
0

在我的UIViewController中,我有一个UITableView作为子视图之一。添加我UIRefreshControl用下面的代码:iOS - UITableView的UIRefreshControl与UITableViewController的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一个更加不同。

单独的UITableViewUIRefreshControl在拖动时比较慢,我通常必须拖动FARTHER才能让它开始刷新。

在我的其他屏幕上,我的UITableViewControllerUIRefreshControl在拖动时速度更快,而且我不必拖动到目前为止就可以开始刷新。

我喜欢UITableViewControllerUIRefreshControl的平滑行为,让我怎么得到我的UIRefreshControlUITableView的行为更像是属于UITableViewController默认的?

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

回答

1

UIRefreshControl旨在与UITableViewController;在苹果的网站上它说:

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

这就是说,人们已经成功没有UITableViewControllerUIRefreshControl without UITableViewController。使用风险自负。

+0

感谢您的链接!我对使用hacky的'UITableViewController'实例解决方案有点犹豫,但它工作完美! – Rafi