UIButton & UITextField will block UITableViewCell being swipe to delete - ios

There are UIButton and UITextField in the UITableViewCell. The delete button will not come up when I swipe over UIButton or UITextField. I do search for the answers on SO and google, there is a similar questions Swipe left gestures over UITextField, but no correct answers.
I got this problem on iOS 8.
Edit
After setting self.tableView.panGestureRecognizer.delaysTouchesBegan = YES;, it works perfect for cell with UITextField. But when i drag start from the UIButton, the delete button shows and the UIButton fired, which I do not want the UIButton get fired.

I don't know how to prevent the UIButton from firing in the first place, but UITableViewCell has the property showingDeleteConfirmation that can be used to check whether the Delete button is being shown. What I do is check this in the UIButton action for TouchUpInside, like this
- (void)buttonPressed:(id)sender
{
if (!self.showingDeleteConfirmation) {
// Handle button press
}
}
(This example is from a UITableViewCell subclass, so it uses self to access the property.)
This, in addition to the
tableView.panGestureRecognizer.delaysTouchesBegan = YES;
that you already have, works to get the swipe properly recognized and the button action not performed.

Related

Swift UIScrollview double tap uitbutton zoom

I have a view hierarchy like this:
UIView -> UIScrollView -> UIView (contentView) -> UIButton
I have added code to the UIScrollView to activate zoom when the user double tap.
This is working well, the content view and the UIButton are zooming.
In my content view, I have some UIButton, my problem is when I double click on this button, I want the scroll view to zoom (this is ok) but I don't want my button to fire the event (this is not ok)
I want the button to only fire an event if the user click on it one time, but not with double tap.
In my case, the UIButton can be small, and I want the user to get the possibility to double tap on it to zoom, but to fire an action only if it is a one click.
I try to do this with swift
thanks a lot for your help
Instead of UIButton, use UIView or UIImageView as button and add UITapGestureRecognizer to it.
And implement the following logic:
if the view is double tapped {
call your zoom function
}
if the view receives single tap {
then perform your button click function
}
Hope it helps :)

Why a UIButton on UITableViewCell only drawn darker when touch gesture continued for a short time

Pressing the button quickly and not holding for a short time, will not highlight the button.
Different from a UIButton on a common UIView.
Like the head photo in official Twitter client got same issue.
Instagram client seems solved this, all buttons works fine.
Find same question here:
Why doesn't UIButton showsTouchWhenHighlighted work when the button is on a UITableViewCell?
But I still don't know how to fix it.
Well... a UITableView is a subclass of UIScrollView and the UIScrollView class is known to eat touches for it's own purpose.
When it realizes the touch was not meant for it, it passes it to it's immediate subview.
This feature is the delaysContentTouches property (which by default is YES).
Which is why, the UIButton shows it's highlighted state only after a extended touch because the touch event was with the UITableView for a short while until it determined whether the touch was meant for scrolling or swiping the cell and on realizing the touch was for neither, it immediately passes the touch event to the subView directly below it.
In case of a quick-tap, the button's highlighted state is bypassed due to this delay and the target selector method is called directly.
To show the highlighted state of the button in a UITableView (just as it would on a UIView) do:
For iOS7+:
In -viewDidLoad or anywhere appropriate do:
[yourTableViewObject setDelaysContentTouches:NO];
Also... The cell.subviews has a class UITableViewCellScrollView which apparently is another scrollView and we need to disable the delaysContentTouches property of this class as well.
So... in the -cellForRowAtIndexPath: method (just before return cell;) do:
NSArray *test = cell.subviews;
for (UIView *currentView in cell.subviews) {
if ([NSStringFromClass([currentView class]) isEqualToString:#"UITableViewCellScrollView"]) {
UIScrollView *svTemp = (UIScrollView *) currentView;
[svTemp setDelaysContentTouches:NO];
break;
}
}
For iOS 6-:
In iOS6, the cell.subviews has a UITableViewCellContentView class which is not a scrollView subclass and so all it takes is setting one parameter for the tableView alone.
So, in -viewDidLoad or anywhere appropriate, this is all that you need:
[yourTableViewObject setDelaysContentTouches:NO];
PS: By doing this, it will mess up with the scrolling of the tableView so use your better judgement.

UITableView on a UIView with UITapGestureRecognizer (cell selection doesn't work)

I have some problems with using a UITableView on a UIView which haves a UITapGestureRecognizer.
If I click on a UITableViewCell, the background does not change to the selected one (because no touch is received).
I was in the assumption that if you add a childview to a parentview, the childview would be able to handle the touch and that everything would still work. However, this is not the cas. If I tap on a UITableviewCell, the tap is handled by this parentview and the cell is not selected.
I already tried to subclass "UITapGestureRecognizer" to ignore touch events from UITableViewCell:
(monotouch code)
public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
{
if (touch.View.GetType () == typeof(UITableViewCell))
return false;
return true;
}
It's not working because of I click on a cell, "touch.View.GetType ()" returns "UIView" and it's ignored.
Any idea's how I can make my tableview working on a UIView with a UITapGestureRecognizer?
If I remove the "UITapGestureRecognizer" from the parentview, the tableview acts normal.
Thanks Matt
When you create your UITapGestureRecogizer set the setCancelsTouchesInView property to NO. That should allow your UITableViewCell to receive the touch.

Keyboard not showing-up for UITextField in UITableViewCell in iOS 6.x

Working on iPhone/iPad application,
Problem: Keyboard not showing-up for UITextField in UITableViewCell in iOS 6.x, but same code works fine on iOS 5.x
We developed a UIViewController, in which we tableview is created. In this tableview, we have added textfield cell. So textfield shows the cursor, but it doesnot bring-up the keyboard, nor the cursor moves. (Every thing works fine on iOS 5.x)
UITableView *localTable=[[UITableView alloc]initWithFrame:tableFrame style:UITableViewStyleGrouped];
self.tblScheduleBasicInfo=localTable;
[localTable release]; //release the localTable
enter code here
#interface CustomTextFieldCell : UITableViewCell {
UITextField *cellTextField;
}
CustomTextFieldCell *tfCell2;
tfCell2=(CustomTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:textFieldIdentifier1];
if(tfCell2==nil)
{
tfCell2=[[[CustomTextFieldCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:textFieldIdentifier1]autorelease];
}
tfCell2.cellTextField.delegate=self; //set the delegate to self to implement textField delegate methods in self
tfCell2.userInteractionEnabled=YES;
The delegate is called, but keyboard does not show up.
We have tried following options mentioned in SO, but no luck yet
SO Link 1
SO Link 2
SO Link 3
All suggestions are welcome.. Many Thanks in advance.
Until you tap on cell, your table cell will be the event responder. To make keyboard appear over text field, you need to make your text field to consume event respond as :
In tableView:didSelectRow:atIndex method :
[self.cellTextField becomeFirstResponder]

IBAction UIButton firing is delayed

I have a UIButton connected to an IBAction in Interface Builder.
The Problem:
The action firing and the de-highlight of the button both take a little bit to happen.
The Facts:
View structure:
View
10 Buttons (connected via UIControlEventTouchUpInside to the IBAction
View (Subview)
Gesture recognizer
Text Field
The Subview has a UITapGestureRecognizer, which delaysTouchesBegan and delaysTouchesEnded both are set to NO
The action is happening in the main thread.
Testing a simple button (with no images or title, and only a simple NSLog), the result is the same
The Question:
Why are firing and the de-highlight delayed?
In the end, I added somewhere some UIGestureRecognizer, and forgot to set delaysTouchesBegan to NO =(
Ok I think that because of the UITapGestureRecognizer .. try to do the following :
connect an IBOutlet to your button.
2.assing the UITapGestureRecognizer delegate to your ViewController.
3.Implement this gesture delegate method in yourViewController
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
return (! [yourButton pointInside:[touch locationInView:yourButton] withEvent:nil]);
}
This will make the tap to be recognized to your button not to the recognizer.
Make sure your touch event is set the first contact of the button which would be the touch down event otherwise there will be a delay in the action until whichever other event you chose gets completed (i.e. touch up inside, touch up outside, etc).
In my case, there was a delay on IBAction for a button that was in a custom CalloutView of an MKAnnotationView.
In the same way there is a ~0.5sec delay between pressing the MKAnnotationView and the MKAnnotationView actually being selected, there is also a delay between any other user interactions you might add as a subview of the MKAnnotationView.
The solution is to disable the native UIGestureRecognizer within MapView that is causing the delay of any MKAnnotation view selections.
This can be done with the solution on this post:
Set isZoomEnabled = false within a gesture recognizer attached to the mapview on any tap, then set isZoomEnabled = false within a 0.5sec async dispatch.

Resources