1

I want to write an action when user scroll up from UITableView,How can I do this ?

  • 1
    http://stackoverflow.com/questions/2543670/iphone-sdk-finding-the-direction-of-scrolling-in-uiscrollview may help – Praveen-K Mar 05 '13 at 15:18

3 Answers3

6

Try this

Step 1:

   yourUITableView.delegate = self;

Step 2:

   CGFloat yOffset = 0.0;

Step 3:

 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
        {
            if (scrollView.contentOffset.y < yOffset) {

                // scrolls down.
                yOffset = scrollView.contentOffset.y;
            }
            else
            {
                // scrolls up.
                yOffset = scrollView.contentOffset.y;

                // Your Action goes here...
            }

        }
Vedchi
  • 1,200
  • 6
  • 14
0

There are several ways I can think of that can help you with this. For once, if you don't need to have a precise recognition of the upward swiping you can use the UITableView behaviour to do this.

Each time a new row appears, tableView:cellForRowAtIndexPath: selector is called. You can use this method to know de direction the user is scrolling by comparing the previously inserted row (indexPath.row) to see if the newer is lower. If it is, then the user is scrolling up.

For more precision you can try using the Swipe Gesture Recognizer. I've personally never used it, but I can't imagine it being hard to use.

JavaZava
  • 108
  • 1
  • 5
0

UITableView inherits from UIScrollView, so you can use the delegate from UIScrollView for your tableView: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollViewDelegate_Protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intf/UIScrollViewDelegate

tableView.delegate = self;

..

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
   NSLog(@"Content offset: %f", scrollView.contentOffset.y);

   // do something like
   // if firstOffset < secondOffset {
   // [self yourAction];
   //}
}
etolstoy
  • 1,798
  • 21
  • 33
Retterdesdialogs
  • 3,180
  • 1
  • 21
  • 42