我已经在UITableview中添加了两个自定义原型单元的pull来刷新,我已经尝试了这两种类型的代码,通过添加UIRefreshcontrol作为tableview的子视图,其他通过UITableViewController
1)UIRefreshcontrol作为tableview的子视图
self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.tintColor = [UIColor blackColor];
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[listTable addSubview:self.refreshControl];
2)通过UITableViewController
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = listTable;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshContacts) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;
但两者似乎都不起作用。
答案 0 :(得分:0)
检查这些链接以获取信息
UIRefreshControl - Pull To Refresh in iOS 7
实施例
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];
}
答案 1 :(得分:0)
第二种方式几乎与我在What's the Best Way to Get a "Pull to Refresh" from a UITableView?中建议的代码相同,所以我认为你的bug在tableViewController中。它被保留了吗?
答案 2 :(得分:0)
在.h
@property(nonatomic,strong) UIRefreshControl *refreshControl;
在.m
- (void)viewDidLoad {
[super viewDidLoad];
//Initialize the refresh control
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshBrandList:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:self.refreshControl];
}
-(void) refreshBrandList:(id)sender{
[self ServiceCall];
[self.refreshControl endRefreshing];
}
答案 3 :(得分:0)
SVPullToRefresh + SVInfiniteScrolling