现在很多应用软件中有下拉刷新这回事,下拉刷新是apple在IOS6.0以后添加的一个新控件,接下来为大家详细解答UIRefreshControl这个控件首先我们先看系统头文件:对于UIRefreshControl只有寥寥无几的3个属性和2个方法
下面我阐述一下个人见解,
@property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing; //用来判断是否进入刷新状态
@property (nonatomic, retain) UIColor *tintColor;
@property (nonatomic, retain) NSAttributedString *attributedTitle //属性对象字符串,主要用来显示本控件在下拉状态的时候,控件的title信息
/ May be used to indicate to the refreshControl that an external event has initiated the refresh action
- (void)beginRefreshing NS_AVAILABLE_IOS(6_0);//系统调用
原因:主要是表示由于对refreshcontrol外部事件引发的刷新动作
// Must be explicitly called when the refreshing has completed
- (void)endRefreshing NS_AVAILABLE_IOS(6_0);//该方法必须显示的调用,用来终止刷新
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"下拉刷新测试";
NSDate *myDate = [[NSDate alloc]init];
[self.myModel addObject:myDate];
[self.tableView registerClass:[LSTableViewCell class] forCellReuseIdentifier:@"Cell"];
//下拉刷新测试代码
UIRefreshControl *myRefresh = [[UIRefreshControl alloc]init];
myRefresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"开始下拉刷新"];
[myRefresh addTarget:self action:@selector(refreshMethd) forControlEvents:UIControlEventValueChanged];
self.refreshControl = myRefresh; //tableView中的一个系统属性
}
-(void)refreshMethd{
if (!self.refreshControl.refreshing) {
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"加载中..."];
NSDate *mySecdate = [[NSDate alloc]init];
[self performSelector:@selector(callBackMethod:) withObject:mySecdate afterDelay:1];
}else{
NSLog(@"This is not Refresh!");
}
}
-(void)callBackMethod:(NSDate*)objdate{
[self.refreshControl endRefreshing];
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"结束下拉刷新"];
[self.myModel addObject:objdate];
[self.tableView reloadData];
}
如有错误,欢迎大家指正。感谢!