2016-05-13 70 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