IPhone scrolls UITableview, choosing side of table

In my case, I have a UIView and a UITableView. I want to scroll the table view by checking the UIView. I added napkins and make gestures for UIView. When I scroll this view, scroll the table view along the swipe direction. Is it possible?

+4
source share
2 answers

Call this method from your viewDidLoad. This method will disable table scrolling to prevent manual scrolling. Assuming you have 100 rows 30 in height and myview is the view you have to scroll through. In my view, scroll gestures are added, it is important to set the direction of movement

- (invalid) initialSetup {

[self.tableView setScrollEnabled:NO]; int numberOfRows=100; int rowHeight=30; myview=[[UIView alloc]initWithFrame:CGRectMake(280, 0, 30, numberOfRows*rowHeight)]; [myview setBackgroundColor:[UIColor yellowColor]]; [self.view addSubview:myview]; UISwipeGestureRecognizer *swipeDown=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(motion:)]; [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown]; [myview addGestureRecognizer:swipeDown]; UISwipeGestureRecognizer *swipeUp=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(motion:)]; [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp]; [myview addGestureRecognizer:swipeUp];} 

The following method will be called when the swipe gesture is either swipeUp or swipeDown. When the method receives the swipeUp gestures, it scrolls the last row currently visible in the table view at the top. When the method receives swipeDown, it scrolls the first row that is currently visible at the bottom

- (void) motion: (UISwipeGestureRecognizer *) sender {

 if (sender.direction==UISwipeGestureRecognizerDirectionUp) { [self.tableView scrollToRowAtIndexPath:[self.tableView.indexPathsForVisibleRows objectAtIndex:[self.tableView.indexPathsForVisibleRows count]-1] atScrollPosition:UITableViewScrollPositionTop animated:YES]; }else if(sender.direction==UISwipeGestureRecognizerDirectionDown) { [self.tableView scrollToRowAtIndexPath:[self.tableView.indexPathsForVisibleRows objectAtIndex:0 ] atScrollPosition:UITableViewScrollPositionBottom animated:YES]; } 

}

+2
source

// let myView be the view from which you want to scroll the table (myTableview)

// now add the following lines to your viewdidload method

 UISwipeGestureRecognizer * swipegesture = [[UISwipeGestureRecognizer alloc]init]; swipegesture =[myTableview.gestureRecognizers objectAtIndex:1]; [myView addGestureRecognizer:swipegesture]; 
+2
source

All Articles