Select tablecell when touching embedded view - iphone

I have a custom tablecell with an embedded MapView showing a small area. When the user selects the cell, I want to push a new view with a larger mapview and some more information, like distance from where you are, option of what map-type etc.
If I leave a small margin around my mapview, the user can click in that margin to select the cell, but how can I make the cell selected if they click inside the mapview?
regards,
-Vegar

I think you need to override the hitTest method inherited from UIView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
This method traverses the view
hierarchy by sending the
pointInside:withEvent: message to each
subview to determine which subview
should receive a touch event. If
pointInside:withEvent: returns YES,
then the subview’s hierarchy is
traversed; otherwise, its branch of
the view hierarchy is ignored. You
rarely need to invoke this method, but
you might override it to hide touch
events from subviews.

Try set MapView's userIteractionEnabled property to NO

Related

touch events on UITextField rightView

I have several text fields which compromise a registration form . When the user hit submit and made invalid inputs the wrong fields are marked with an icon as rightView.
The rightView i use is a custom UIImageView subclass which has it's:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
overwritten to display a alert to tell the user what exactly is wrong with this field.
The problem is that the touchesBegan method is never called. Why is the view not receiving touch events when I touch it?
you need to enable user interaction of images to TRUE
[imageView setUserInteractionEnabled:YES];
You should check whether your view is on the upper level of views (that it's not overlayed by another transparrent view)
And also check for view's user interaction set to ENABLED
Also check that you tap directly on the view, this method is called only when you tap within your view's bounds
I also recommend you to read a bit about UITapGestureRecognizer class may be this would be more convenient way to use...

Touch underlying view with nextResponder

Currently I am trying to recreate the Twitter (iPad) type control. Mostly because all the versions available online are not really working for the type of application I am developing, and I think I can do better of course ;) (but it is harder than I thought).
What I want:
Flexible positioning of the view controllers I add to the control
No need to change my current view controllers when I want to use them in my control (mainly because I use the view controllers in the iPhone and the iPad version).
Being able to drag the view controllers around, but still keep al functionality in the view controllers.
What I currently got:
Good positioning on the view controllers, when they are added to my control.
Able to drag the view controllers around, according to the rules I have set (maximum x position etc)
My problem is that when I add a UITableViewController, I want to be able to drag it around AND keep the functionality of scrolling and selecting cells in the table.
My current solution is, that when a view controller is added to my control, I add a subview to it (with the same size of the view controller) which accepts all the touches. These touches are then send to the control, by using a delegate and calling methods on it. This works well, accept that when I add a subview to my UITableViewController, there is some weird behavior. Scrolling up and down still works in the UITableViewController, but these touches aren't detected by the View on top of the UITableViewController. Selecting cells in the table does not work anymore, because these touches are taken by the overlaying UIView.
I add the overlaying UIView to the UITableViewController like this:
SNOverlayView* layover = [[SNOverlayView alloc] initWithFrame:CGRectMake(0,0, controllerWidth, self.frame.size.height)];
layover.delegate = self;
[controller.view addSubview:layover];
[layover release];
My custom overlay UIView contains a couple of these methods, for all the touch (began, ended, cancelled and moved) methods:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([delegate respondsToSelector:#selector(overlayTouchesBegan:touches:event:)])
[delegate overlayTouchesBegan:self touches:touches event:event];
NSLog(#"%#", self.nextResponder);
[self.nextResponder touchesBegan:touches withEvent:event];
}
From what I understand from the documentation, the call to the nextResponder, should make sure that the TableView below my view also receives the touches. But these methods only get triggered when I touch the screen once OR slide sideways. Sliding from up to down does not trigger these methods and touching a cell does not trigger the didSelectRowAtIndexPath from the UITableViewController. The self.nextResponder in this method is a UITableView (which is outputted by the NSLog in that method).
I am misunderstanding the nextResponder part? Isn't this possible when not modifying my UITableViewController?
EDIT: I updated the structure which I add to my main UIView containing all ViewControllers:
|- Root UIView (1)
|-- Containment UIView which detects touches (2)
|---- UITableViewController (3)
The problem is that now my containment view (2) does not detect touches. I will try to update my code to make it more like the structure mentioned below:
|- Root UIView (1)
|-- Containment UIView (2)
|---- UIView detecting touches (4)
|---- UITableViewController (3)
But I am not sure how I can get the UIView to detect touches. because when I add the UITableViewcontroller (3) to my containment UIView (2) it will be put on top of the UIView detecting the touches (4) and therefor 'stealing' the touches. I would rather change the order of (4) and (3).
Are you adding a subview to a UITableView? This is dangerous, because it will scroll with the cells (UITableView is a sub-class of UIScrollView), and because the UITableView adds and removes subviews itself too, so you can't control the order that the views are in.
I think your best bet would be to have a view hierarchy like this
- containerView (plain UIView, that your UIViewController loads)
|-- overlayView (catches touches)
|-- UITableView
That being said, I've got a suspicion that UIScrollViews use a different method for grabbing touches to other UIViews (i.e. not touchesBegan: etc.).

How to recieve touches began event inside a subview?

I have a view containing two subviews(plain UIviews). The parent view recognizes touch events like touchesbegan ,ended, etc. but the sub view is not recognizing the touch event. How to make it recognize the touch event. Specifically i need only sub view to recognize touch events and not parent view. Thanks in advance.
UserInteractionEnabled is set to YES for the views.
There's two ways of dealing with this.
1) Detect the touches in your viewcontroller instead of in a view. You should be able to work out which view contains the point which was touched and from that can decide what to do with the touch (or just throw it away if it wasn't in either view).
2) Create a subclass of UIView and add these to your main view instead of just UIViews. Then you can detect the touches inside your subclass and deal with them accordingly.
Hope that helps.

fire event when touch up inside uiview and outside button

I have a view overlayed to the iPhone's camera view. In this view I have some uibuttons that are displayed in positions depending of values from accelerometer/compass.
I need to fire an event when the user touch up inside the view but he doesn't touch up inside the uibuttons, I mean, the opposite action of touch up inside the uibuttons.
Anyone knows a kind to do this?
Thanks!
If you implement the UIResponder touchesBegan:withEvent: method..
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
...on your view, you'll be able to tell when the user has pressed outside of the buttons.
See the UIResponder Class Reference for more information.
you may e.g. assign one event handler (IBAction) to UiVeiw and its UIButtons and then compare sender parameter:
-(IBAction) viewClicked :(id) sender {
if (id == myView) ...
}
I tried your options but it doesn't work. The view that I tried to fire the event was in a TabBar item in a camera view, so I think the responders chain doesn't work with it.
Finally, I solved the problem doing the overlay view the first responder with:[viewOverlay.view becomeFirstResponder];

Display tooltip on UITableView in iPhone

I was wondering if anyone has tried it. I need to show a tooltip within a table view when the user selects a word in the row's text.
Can you please help me or suggest any way for this?
Thanks in advance!!!!!!
In each cell add a UIView (be it a UITextView, UIImageView or whatever, in fact you can add plenty of additional subviews to it). Say you call it "tooltipView".
Now when user selects text, all you have to do is position (move around) that view near the selection (or where the user touched the row) and set the relative information. To track the selection, you can simply override the - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event method of your cell class and keep checking the point variable and corresponding event.