I have added pull to refresh in UITableview with two custom prototype cells ,I have tryied with these two type of code one through adding UIRefreshcontrol as a subview of tableview and other through UITableViewController
1)UIRefreshcontrol as a subview of 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)Through 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;
But neither both of them seems to work.
Check these links for information
UIRefreshControl - Pull To Refresh in iOS 7
Example
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];
}
The second way is nearly identical to the code I suggested in What's the Best Way to Get a "Pull to Refresh" from a UITableView? , so I'm thinking that your bug is in the tableViewController. Is it getting retained?
In .h
@property(nonatomic,strong) UIRefreshControl *refreshControl;
In .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];
}
SVPullToRefresh + SVInfiniteScrolling
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.