UICollectionView中的下拉刷新

问题

使用下面的代码增加下拉刷新:

var refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: "reTryButtonClicked:", forControlEvents: UIControlEvents.ValueChanged)
refreshControl.attributedTitle = NSAttributedString(string: "松开后刷新")
self.collectionView.addSubview(refreshControl)

但好像总是不起作用

解决

需要设置collectionView的alwaysBounceVertical,参考documentation

alwaysBounceVertical
A Boolean value that determines whether bouncing always occurs when vertical scrolling reaches the end of the content.
Declaration
SWIFT
var alwaysBounceVertical: Bool
OBJECTIVE-C
@property(nonatomic) BOOL alwaysBounceVertical
Discussion
If this property is set to YES and bounces is YES, vertical dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NO.

这个属性用来控制遇到边框是否回弹, 但是 tableView 貌似是不用的

self.collectionView.alwaysBounceVertical = true
2015-07-15 17:071