Oleg
Oleg

Reputation: 3014

iphone - UIGestureRecognizer prevents UITableView from scrolling in Xcode 4.5

I have added two swipe gesture recognizers (swipe left and swipe right) to my UITableView. After that my table view has stopped scrolling. At the same time -(void)didSelectRowAtIndex works fine. What might be the problem?

All I did is drag-and-dropped Swipe Gesture Recognizers from objects library onto my UITableView.

If I remove them, my table starts to scroll again.

UPD:

This happens after upgrading to Xcode 4.5. There is no such problem in older versions of Xcode. To avoid this behaviour - add UIGestureRecognizers programatically, not in IB.

Upvotes: 6

Views: 3670

Answers (4)

Pedro
Pedro

Reputation: 104

I faced this same problem and I solved it by linking the gesture recognizer to the view instead of to the table view.

  1. Show the storyboard.
  2. Show the connections inspector.
  3. Show the document outline.
  4. Create new link at "Referencing Outlet Collections" between gesture recognizer and view node under the view controller.

Regards. Pedro.

Upvotes: 0

Brabbeldas
Brabbeldas

Reputation: 1949

I had the same issue: I used to drag my TabGestureRecognizer directly onto the storyboard instead of creating them through code. With iOS6 this now seems to break scrolling.

I prefer adding views, gestures, etc directly onto the storyboard instead of through code.

You can still do this but with two changes:

1) Referencing Outlet Collections

  • Right-click the GestureRecognizer which is visible to you within the scene's dock.
  • Clear the section Referencing Outlet Collections

2) Attach the GestureRecognizer to the related view through code

  • Create an outlet for your GestureRecognizer
  • Add the following line within the viewDidLoad method:

    [self.tableView addGestureRecognizer:_tabGesture];

Upvotes: 1

Paras Joshi
Paras Joshi

Reputation: 20541

just try bellow code may this help you.... write bellow code in viewDidLoad: method

UISwipeGestureRecognizer *swipeGestureObjectImg = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(yourSlideOpen_Clicked:)] autorelease];//yourSlideOpen_Clicked is method name where you doing something
swipeGestureObjectImg.numberOfTouchesRequired = 1;
swipeGestureObjectImg.direction = (UISwipeGestureRecognizerDirectionLeft);
[yourView addGestureRecognizer:swipeGestureObjectImg];

UISwipeGestureRecognizer *swipeGestureRightObjectImg = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(yourSlideClose_Clicked:)] autorelease];//yourSlideClose_Clicked is method name where you doing something
swipeGestureRightObjectImg.numberOfTouchesRequired = 1;
swipeGestureRightObjectImg.direction = (UISwipeGestureRecognizerDirectionRight);
[yourView addGestureRecognizer:swipeGestureRightObjectImg];

if here tableview is subview of UIView class then use above code otherwise just try "youtTableview" insted of "yourView"

i hope this help you...

:)

Upvotes: 6

Mitrodan
Mitrodan

Reputation: 73

set property of gesture recognizer cancelsTouchesInView = NO

Upvotes: 1

Related Questions