Touch events aren't reaching touches methods? - iphone

I have a View Controller, and a UIImageView as a subview. That UIImageView also has a subview of that same type.
I have:
self.userInteractionEnabled = YES;
set for each. My touchesEnded code was working. Any idea what would cause this? No touches are even reaching the touches events. I don't understand?
Any help appreciated.
Thanks // :)

Sounds like you've gone all the way up the chain and checked the self.userInteractionEnabled all the way up to the top, right? Ok, now check if any view has exclusiveTouch set to YES.
Also, if you called resignFirstResponder on the parent view, instead of a UIText field, you would relinquish events.
Lastly, beginIgnoringInteractionEvents, can cause this too.

I just found this solution from saimhann2002 who was having a similar problem.
Thanks for the reply. I have been able to fix the problem now. The issue was that I was adding the subview to the MKMapView rather than the view of the ViewController. I don't know why this is an issue. If you do I would be interested to hear. Adding the view as a subview to the view of the ViewController fixed everything, with the view now accepting the touches, even when its colour is UIColor clearColor.
That works!

Related

UITextField in UITableViewCell

I have a standard UITableViewController. In the cellForRowAtIndexPath I add a subview to cell.contentView. This UIView itself contains a UITextField object. This object will not respond to touches. I have set the delegate to the UIView and implemented all the methods. I have also set userInteractionEnabled = YES. When I tap the UITextField nothing happens! I feel it's being absorbed by the cell. What would be the easiest, least messy fix?
Best,
Joris
EDIT: Sorry, see my answer. I solved it.
I'm an idiot. Sorry for wasting everyone's time. I hadn't properly said the UIView's frame. It of course did display the UI elements, but wouldn't respond to them.
Try just adding the textfield as a subview of the cell, this is what I have done in a couple of my apps and had no problems with it
In your tableView, try to set
allowsSelection = NO;
Try setting the editing property of the table view to YES.
Check this answer
Editing a UITextField inside a UITableViewCell fails

UIButton under UIView should NOT be clickable

I have a view with some UIButtons on it. I add another - semi transparent - view on top of all, displaying some information to the user (actually, it's kind of a selfmade modal-alert). But the buttons under the semi-transparent view still react to taps. They shouldn't, though.
How can I prevent the buttons from reacting to taps?
Setting,
semiTransparentViewOnTopOfAll.userInteractionEnabled = YES;
should solve this problem. But, still if the problem persists, try,
semiTransparentViewOnTopOfAll.exclusiveTouch = YES;
do like this
button.userInteractionEnabled=NO;
by getting all buttons from view

Accessing superview ScrollView?

i added some views (every view has its own viewcontroller and nib) to an UIScrollView. How can I access the ScrollView from within the UIViews I've added?
self.view.superview doesn't get me the UIScrollView properties. I need to disable scrollEnabled from within an UIView.
Thank you!
Maybe try (UIScrollView*)(self.view.superview).property to access the property you want :-)
It should work.
But maybe with an Delegate it would be better :-p
Good Luck !

Can't touch UITextField on UIScrollView

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.

Touch events not working on UIViews inside UIScrollView

I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. If I take the views out of the scroll view then it works.
I have enabled userInteraction on the views but it's still not working!
This must be possible and I'd be really grateful if someone could point me in the right direction!
Thanks,
Mike
Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller.
I have overcome this issue by overriding the loadView method of the view controller, and setting the view's instance variable to a simple UIView subclass which passes on the touches.
Check what you are returning in scrollview delegate method view for scrollin in scroll view.
As mahboudz mentioned - check if you have any custom handler for touch event. If not, please have one. Its far more relief to do whatever you want to do with your view. Check out Apples sample app from scrollViewSuite. They have tapDetectingImageView delegate. I used the same in my app it worked great! Hope this helps!
You may find this post useful. It's an example of a pretty clean way of intercepting events.
Have touch handlers for view for which you want to receive touch events and that will work.