UITableview only allow swipe to delete in one direction - iphone

I have a tableview in which Edit mode is enabled, so the user can swipe in any direction on a cell to bring up the delete button. However, I have a gesture on the whole tableview for right swipes to do something else, unrelated to the deletion. I would like it if the swipe to delete only worked on a left swipe, so that my gesture recognizer would be called on the right swipe. Right now, the tableview swipe completely overrides my gesture recognizer.
Is there any way to fix this?
Thanks,

You just need to add a SwipeGesture to tableView and important thing is do not set the delegate of swipeGesture and do not implement gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer function.
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(callYourMehod:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.table addGestureRecognizer:swipeRight];
It should work as I have implemented and used it in my code
This is how table cells will not go in edit mode on right swipe.

Related

UISwipegesture not working with UITableview

UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(resignTextView)];
swipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionDown;
swipeGestureRecognizer.numberOfTouchesRequired=1;
[self.tableview addGestureRecognizer:swipeGestureRecognizer];
-(void)resignTextView
{
[textView resignFirstResponder];
}
I do not know Why resignTextView method not get called?
The tableview has a scrollview and you can get the delegates of it to get the scroll events.
Check the docs for the UIScrollViewDelegate protocol, and implement the -scrollViewDidScroll: or -scrollViewWillBeginDragging: methods as appropriate to your situation.
Just implement the methods and it works since the tableview delegates implements the underlying scroll delegates.
You are adding Swipe Gesture on Table View and in Downword direction. As you know Table View already has a Scroll and it scrolls upward and downward direction. If you add a Swipe Gesture in Downward direction. Then every time when you swipe in downward direction calls scroll methods of scroll and table moves scroll and device layer detect no swipe action, so ur method not called. In a very few situation when sometime there is less cell and table is not scrolling then try to check it again ur swipe method get called. Both swipe in downward direction and scrolling are not works properly in simultaneously.
you missed : after resignTextView

Get the Direction of Swipe Before Scrolling a UIScrollView

Is there a way to get the direction of swipe before the scrolling the UIScrollView?
I tried to add swipe gesture but no luck.
Here is the event I want to handle. If I swipe fast sideways, left or right, and down-ish, I want it scroll else don't scroll. Also I want to get the interval of swipe. Is there a possible way to do those things? Thanks.
You can use UISwipeGestureRecognizer control.Use UISwipeGestureRecognizerDirectionLeft for gettting Direction.
For that have look at this code below:
UISwipeGestureRecognizer *oneFingerSwipeLeft = [[[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:#selector(oneFingerSwipeLeft:)] autorelease];
[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:oneFingerSwipeLeft];
In oneFingerSwipeLeft function you can have the direction. Follow the same process for right swipe.

Make UITextView react to tap event. (iphone)

I'm trying to implemet a scrollable Text view (not editable) that display some help information etc. and when the user is done with it all he has to do is tap it and it will disapear/hidden and the user will be back in the main screen.
The UITextview not reacting to tap event (or i'm not sure how to make it react to the tap event).
Any idea how to implement this ?
I also tried to put it inside a transparent button so i can capture the tap but then i cannot scroll the text view as it seem to be behinde the button.
i'm new to iphone , any help... gr8
Thanks
How about adding a tap gesture recognizer to the text view?
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(textViewTapped:)];
[yourTextView addGestureRecognizer:gestureRecognizer];

How can I capture a sideways swipe gesture for a tableView that is inside of a pageControl?

I have a tableView that is one of the views inside a pageControl. I want to be able to capture and respond to a sideways swipe gesture if it's within the tableView, and have the pageControl respond if it is outside of the tableView.
How can I do this?
As I see it, since swiping the table for an action and swiping the table to change pages is pretty much the same motion, you would just have to disable scrolling on the scrollview, scrollview.scrollEnabled = NO; and create a gesture recognizer for your table view, UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: #selector(myAction:)]; I haven't tested this code so please let me know if you run into any problems.

Interrupting a scrolling/animating UIScrollView with a UIGestureRecognizer

I have a UIScrollView and a UITapGestureRecognizerwhich are both pretty basic, and have got them to work together in every way I need except one. The UIScrollView doesn't use any zooming, and the UITapGestureRecognizer just writes to the console for now.
I can get the UITapGestureRecognizer to write to the console when the UIScrollView is tapped, either while stationary or animating through setContentOffset, but I cannot get it to work when the UIScrollView is moving due to being swiped. When the UIScrollView is swiped and still in motion, the first tap after swiping will stop it moving, and then only the second tap is picked up by the UITapGestureRecognizer. I hope to get the first tap to both stop the UIScrollView from scrolling and also write to the console through the UITapGestureRecognizer.
I hope that my problem here is just through a gap in my knowledge of either the UIScrollView or UITapGestureRecognizer and there is just a Property to set to fix this, but so far no amount of reading has helped me with this issue. Any ideas on whether this is possible?
Edit: Thanks for the suggestions, please see below
Apologies, I don't think I explained myself very well. I realise the first movement on the stationary UIScrollView is a swipe (which in my case is just handled by the UIScrollView btw, not a gesture recognizer).
The problem is after swiping and releasing, if you tap while it is still in motion (and no other touch is in progress), it isn't picked up by the UITapGestureRecognizer, instead it is only picked up by the UIScrollView and stops the UIScrollView moving. If you let it decelerate then tap, this works fine. Also if it is moving due to an animation but not a swipe, the tap also works fine.
This is the same when using a `UILongPressGestureRecognizer' which is what I want to use ideally, but thought if I can't get it to work with a tap, I have no chance with that!
Sounds like you need to implement the
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
delegate method for your UITapGestureRecognizer and return YES for the UIGestureRecognizers you want to interpret tap gestures in sync with.
e.x.
// Somewhere in your code...
UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
tap.delegate = self;
[self.view addGestureRecognizer:tap];
[tap release];
// And the delegate method...
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
n.b. You may want to be more discriminating in deciding which UIGestureRecognizer(s) you wish to work in sync with. The example will work with every other gesture recognizer.
The problem is that when the user taps the first time to scroll the UIScrollView, this is not a tap, it is a swipe. It would be considered a tap only when the user taps and releases the finger almost at the same position (without dragging the finger through the screen).
What you could do to solve your problem is: use the UIScrollView delegate method scrollViewWillBeginDragging and then you would know when the user just tapped and will start dragging the scrollview, and also add the UITapGestureRecognizer for those real taps.