NS_CLASS_AVAILABLE_IOS
(
6
_0)
@interface
UIRefreshControl :
UIControl
// refreshControl初始化
- (
instancetype
)init;
// 刷新中得状态判断,只读属性,根据状态可做一些自定义的事情
@property
(
nonatomic
,
readonly
,
getter
=isRefreshing)
BOOL
refreshing;
// 菊花以及文字的颜色
@property
(
nonatomic
,
retain
)
UIColor *tintColor;
// 下拉刷新文字描述,自定义
@property
(
nonatomic
,
retain
)
NSAttributedString
*attributedTitle
UI_APPEARANCE_SELECTOR
;
// 开始刷新
- (
void
)beginRefreshing
NS_AVAILABLE_IOS
(
6
_0);
// 结束刷新,在确定获得想要的加载数据之后调用
- (
void
)endRefreshing
NS_AVAILABLE_IOS
(
6
_0);
@end
[使用方法]
1.目前只对UITableviewController有用;
2.只能下拉刷新,不能上拉刷新;
3.init或者viewdidload中创建
UIRefreshControl,设置文字,颜色等信息;
4.系统自动管理
UIRefreshControl,自动添加到tableview视图中;
5.给
UIRefreshControl添加方法,当值改变的时候调用,方法用于数据请求;
6.该方法中请求数据确认完成之后,调用
endRefreshing方法,关闭刷新;
【代码示例】
- (
void
)creatRefreshing {
self
.refreshControl = [[
UIRefreshControl
alloc
]
init
];
self
.refreshControl.
attributedTitle
= [[
NSAttributedString
alloc
]
initWithString
:
@"
努力加载中
……"
];
self
.refreshControl.
tintColor
= [
UIColor
grayColor
];
[
self
.refreshControl
addTarget
:
self
action
:
@selector
(refreshAction)
forControlEvents
:
UIControlEventValueChanged
];
}
- (
void
)refreshAction{
_reloadCount++;
//
请求数据
[
self
requestFromDPAPI
];
//
结束刷新
[
self
.refreshControl
endRefreshing
];
}