有没有办法将刷新控件应用于UITableView
中设置的UIViewController
?
我找到的解决方案需要UITableViewController
的子类化,这对我来说很麻烦,因为我需要子类UIViewController
而不是UITableViewController
,我没有看到任何方法UITableView
的文档,允许我对其设置刷新控件。
非常感谢任何帮助!
答案 0 :(得分:9)
使用此UIRefreshControl
控件:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh1:) forControlEvents:UIControlEventValueChanged];
[Delivered_TBL addSubview:refreshControl];
- (void)refresh1:(UIRefreshControl *)refreshControl
{
[self Service_Call];
[refreshControl endRefreshing];
}
答案 1 :(得分:2)
答案 2 :(得分:2)
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.backgroundColor = [UIColor clearColor];
refreshControl.tintColor = [UIColor whiteColor];
[refreshControl addTarget:self
action:@selector(getLatestData)
forControlEvents:UIControlEventValueChanged];
[yourTableviewName addSubview:refreshControl];
-(void)getLatestData
{
// here add your reload method
[self XXXXX];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
forKey:NSForegroundColorAttributeName];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
refreshControl.attributedTitle = attributedTitle;
[refreshControl endRefreshing];
}