I have a UIRefreshControl
in a UITableViewController
. Is there any way I can detect if a user begins to drag the View down to refresh the content?
I do not mean the beginRefreshing
method. I want to be able to detect when a user begins to drag down - like when the circle fills up before the beginRefreshing
method is called. Is this possible?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
As you have implemented UITableViewDelegate
protocol you can also implement UIScrollViewDelegate
which is called on scroll or drag.
Objective C
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
or
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Swift
func scrollViewWillBeginDragging(scrollView: UIScrollView)
or
func scrollViewDidScroll(scrollView: UIScrollView)
Implement UIRefreshControl
without UITableViewController
Add a scrollview and put this code in your viewDidLoad
let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
ScrollView.addSubview(refreshControl)
ScrollView.contentSize = CGSizeMake(320, 800)
Add this method
func refresh (sender:AnyObject)
{
print("Refresh")
}