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.
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...
:)
set property of gesture recognizer cancelsTouchesInView = NO
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];
I faced this same problem and I solved it by linking the gesture recognizer to the view instead of to the table view.
Show the storyboard.
Show the connections inspector.
Show the document outline.
Create new link at "Referencing Outlet Collections" between gesture recognizer and view node under the view controller.
Regards.
Pedro.
Related
I have created one common view for the application where I have added container view.
This is a confusing structure also very common question for SO but I am stuck since a day..
In my case hierarchy is as
ViewController's View -> (within that) commonview's container view -> (within that)I am adding one another view(base view) with two views.(view 1,view 2)
[self.commonView.containerView addSubview:baseView];
[baseView addSubview:view1];
[baseView addSubview:view2];
[self.view addSubview:self.commonView];
For that I am getting click events for view1's buttons but not for the view2's buttons.
I have checked userInteraction and all other common things. Now I am not getting what is wrong. Also this structure is already used in application so I wont be able to change it.I just have to resolve this issue.
Please check, if you have applied Gesture to any view then make cancelsTouchesInView property of gesture to NO. By default, it is TRUE, so button inside that view may not get touch as gesture cancels its inner view's touch.
If this is not the case, then apply Gesture to your button as this can happen when there are many hierachy of controls.
I think you should try by bringing your subview(i.e. view1) to front, since it is getting hide by another subview (i.e. view2)
You should first try with [self.view bringSubviewToFront:self.commonView.containerView ]; only.
if this works then it's Good otherwise try with this both shown as following
[self.view bringSubviewToFront:self.commonView.containerView ];
[self.view bringSubviewToFront:view1];
Hope this is helpful to you!
Enjoy Programming!
you need to add in respective order.
First add base view1 & view2 into baseView
[baseView addSubview:view1];
[baseView addSubview:view2];
and then add baseView into ContainerView
[self.commonView.containerView addSubview:baseView];
at last add commonView in mainView
[self.view addSubview:self.commonView];
Note :-
If you are adding the viewcontroller into the current viewcontroller then you need to write below code.
[self addChildViewController: yourviewController];
Then your button click will be worked.
i have a point in my app where I remove one scrollview and add another. I want the same gestures in my previous scroll view to be present in the new one.
I have tried:
scrollView.gestureRecognizers = self.scrollView.gestureRecognizers;
But it just gave me a EXC_BAD_ACCESS.
Thank you!
You need to reinitialize the gesture recognizer with the new target. You can't just copy it like this.
UIGestureRecognizer *newGestureRecognizer = [UIGestureRecognizer alloc] initWithTarget:newScrollView action:#selector(yourAction);
I am trying to automate some tests of my ipad application.
I have a scrollview which contains a custom view.
The custom view overwrites the drawRect and has a TapRecognizer.
The custom view is created into the code and I have set this properties
myView.userInteractionEnabled = YES;
[myView setIsAccessibilityElement:YES];
[myView setAccessibilityLabel:#"myView"];
The custom view is added to the scrollview with
[myScrollView addSubview:myView];
Everything works smooth both on device and on simulator: tapping on the view, the tap recognizer callback is called and the custom view can draw something at the tap point.
I would automate the view test and then I need to simulate user's taps on myView.
In the uiautomation script I have something like this:
myView = circuitScrollView.elements()[0];
myView.logElement();
myView.tapWithOptions({x:56, y:576});
to simulate a user tap at position x=56 and y=576.
Nothing happens, it seems that myView doesn't receive any tap (just in case, I play a sound into the TapRecognizer but it has never been sounded).
I have tryed this too:
myView.tap();
no success.
Any idea ?
Thank you in advance.
Fab.
This may be of some use to you. I wrote a test that taps certain x/y coordinates. Rather than touching the scroll view try tapping the window as demonstrated below.
To do so I wrote:
var window = UIATarget.localTarget();
window.tap({x:x_co , y:y_co});
x_co and y_co were my coordinates.
Hope this helps.
Maybe myView = circuitScrollView.elements()["myView"] might help instead of myView = circuitScrollView.elements()[0]; ?
Maybe your custom view is not the first element in the element tree of your circuitScrollView...
I have created a small UIView which contains two UIButtons. The view responds to UITapGesture events. The Buttons are supposed to respond to TouchUpInside, however when I tap the buttons the responder is the underlying view and the tap gesture selector is triggered. Looking for advice or suggestions.
You can modify the method that responds to the tap gesture in the orange view:
-(void) handleTapFrom:(UITapGestureRecognizer*) recognizer {
CGPoint location = [recognizer locationInView:orangeView];
UIView *hitView = [orangeView hitTest:location withEvent:nil];
if ([hitView isKindOfClass:[UIButton class]]) {
return;
}
//code that handle orange view tap
...
}
This way if you touch a UIButton, the tap will be ignored by the underlying view.
The right answer (which prevents the tabrecognizer from highjacking any taps and doesn't need you to implement a delegate etc) is found here. I got a lead to this answer via this post.
In short use:
tapRecognizer.cancelsTouchesInView = NO;
"Which prevents the tap recognizer to be the only one to catch all the
taps"
Each UIView has an 'exclusiveTouch' property. If it's set to YES the view won't pass the touch down the responder chain. Try setting this property on your UIButtons and see if that makes a difference.
How are the views ordered in the view hierarchy? Also, are you creating the interface in IB? If you hook up the connections properly, this shouldn't be an issue at all...
The problem with this design is that it's similar to embedding one button into another. While you may have a valid reason to do it, you should be more careful with the event flow.
What happens is the gesture recognizer intercepting touches before they reach subviews (the two buttons in your case). You should implement UIGestureRecognizerDelegate protocol, namely, gestureRecognizer:shouldReceiveTouch: method, and return NO if the touch is inside any of the two buttons. That will prevent the orange view from usurping touches intended for the buttons and the buttons will start to work as expected.
Check out this question.
uibutton-inside-a-view-that-has-a-uitapgesturerecognizer
I know this has been talked about a lot. I think I've gone thru every question on this site, and still have not been able to get this working.
I'm new to developing but I have a good sense of what's going on with all of my code. I definitely don't have a lot of experience though, this is my first iPhone app.
I'm making a data entry field that is comprised of multiple UITextFields within a UIScrollView. I'll avoid explaining the other details for now, as it seems its a very basic problem. Without a scrollview, the textfields work perfectly. I can touch the textfield and the keyboard or picker view show up appropriately. When I add the textfields to a scrollview, the scrollview works, but then the text fields don't receive my touches.
Here's the key: When 'User Interaction' is ENABLED, the scrollview works but the textfield touches are NOT registered. When 'User Interaction' is DISABLED, the scrollview doesn't work, but the textfield touches ARE registered and the keyboard/picker pops up.
From the other posts I have seen people creating subclasses and overriding the touches in a separate implementation. I've seen people using custom content views (subviews?), I've seen some solutions that are now obsolete since the APIs have changed in newer versions of the SDK, and I am just completely stuck.
I will leave out my code for now, because maybe there is a solution that someone has without requiring my code. If someone needs to see my code, I will put it up. My app is being written in the 3.1.3 SDK.
If anyone has ANY information that could help, it would be so greatly appreciated.
Here is what worked for me in Xcode 4.3.3.
In the storyboard, select your scrollview. Select Attribute Inspector on the right side. Uncheck Delays Content Touches.
It sounds like you're using IB to do a lot of your UI layout. If you take a programmatic approach you could set-up the following view hierarchy which should work.
Your view controller object managing your scroll view and your text fields should have a UIScrollView object and a UIView object (in addition to any UITextField objects you need). In the loadView method of the view controller class, allocate and initalize the UIView object and add your text fields to it as subviews. At the end of the method, allocate and initalize the UIScrollView object then add the UIView to the UIScrollView as a subview.
As an example, if your UIScrollView object were called scrollView and your UIView object called mainView the following lines at the end of the view controller's loadView method would properly set up the scroll view with the main view with the text fields on it:
scrollView = [[UIScrollView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.contentSize = mainView.frame.size;
[scrollView addSubview: mainView];
self.view = scrollView;
You may need to enable / disable user interaction for both the scroll view and text fields as necessary.
If possible you might best using different touch mechanisms for each process (scrolling and textfield input).
Maybe you can check the time differential between touch start and end such that you can detect the difference between a drag (scroll) and a tap (text input).
Having said that if you propagate the touches up from the textfields to the scrollview you should be fine. One thing I use is:
[myObject addTarget:self action:#selector(itemTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
which passes the object touched so you can identify it and act accordingly.