user3267847
user3267847

Reputation: 143

Adding UIRefreshControl to UIScrollView

I'm just trying to simply add a UIRefreshControl to a UIScrollview- for some reason when I pull down on the scroller, nothing happens at all. No ActivityView, no action. It just bounces back up like nothing happened.

this is what I have so far:

- (void)viewDidLoad {
[super viewDidLoad];

[scroller setAutoresizesSubviews:YES];

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.scroller addSubview:refreshControl];

//populate the scroller with data
[self grabData];

}

-(void)handleRefresh:(UIRefreshControl *)refresh {
// Reload my data
[self grabData];
}

Upvotes: 1

Views: 1473

Answers (2)

Mirsat Murutoglu
Mirsat Murutoglu

Reputation: 202

This one should be helpfull

UIRefreshControl *refreshControl;

- (void)viewDidLoad {
  [super viewDidLoad];

  refreshControl = [[UIRefreshControl alloc]init];
  [self.scrollView addSubview:refreshControl];
  [refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; 

}

- (void)refreshData {
  //TODO: reload your data and end refreshing
  [refreshControl endRefreshing];
}

if you are getting some data, after you have complete your receiving data then you should call endRefreshingand reloadData

Upvotes: 2

OSD
OSD

Reputation: 131

What worked for me is make the refreshControl a variable of the class and then use it.

Eg:

class className: UIViewController{
    var refreshControl:UIRefreshControl!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.refreshControl = UIRefreshControl()
        self.refreshControl.addTarget(self, action: Selector("getPrint"), forControlEvents: UIControlEvents.ValueChanged)
        refreshControl.tintColor = UIColor.whiteColor()
        self.refreshControl.backgroundColor = UIColor.clearColor()
        self.refreshControl?.endRefreshing()
        self.scrollView.addSubview(self.refreshControl)
    }
}

Upvotes: 1

Related Questions