Monish Kumar
Monish Kumar

Reputation: 2848

How to make a call to server when I scroll the tableview in iphone sdk?

I would like to send one request when I scroll the tableview up and another request when I scroll down.I dont have any idea how to achieve this.Can anyone suggest me how can I go with this??

Thank you, Monish.

Upvotes: 1

Views: 357

Answers (3)

makaron
makaron

Reputation: 1615

UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate. So the delegate you attach to the table view will get events such as scrollViewDidScroll:, and you can keep track of the instance variable 'contentOffset' of your table view to find out where you tableView was moved up or down.

Also I'd advise you to use something like:

    [NSThread detachNewThreadSelector:@selector(yourRequestMethodInProperThreadBody) toTarget:self withObject:nil];

In order not to affect the movements of your table view when request is being performed.

Upvotes: 0

Maulik
Maulik

Reputation: 19418

The protocol UITableViewDelegate conforms to UIScrollViewDelegate, so all you need to do is to implement the methods -scrollViewWillBeginDragging and -scrollViewDidScroll directly in your UITableViewDelegate implementation and they will be called automatically if the implementation class is set as delegate to your UITableView.

just implement :

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

    NSLog(@"done");

}

Also refer :

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate; // called on finger up if user dragged. decelerate is true if it will continue moving afterwards

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

Upvotes: 3

Sulthan
Sulthan

Reputation: 130102

Use methods from UIScrollViewDelegate. UITableViewDelegate inherits them.

Upvotes: 0

Related Questions