UITableViewController started strokes

I define this method in my subclass of UITableViewController:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; NSLog(@"touch began"); } 

but it does not start. UIViewController is a subclass of UIResponder, so it should work, right? Thanks

+8
objective-c cocoa-touch uitableview uiviewcontroller uiresponder
source share
5 answers

Yes, this should definitely work.

Ensure that User Interaction Enabled is set to the view that this controller corresponds to.

If the view is loaded from nib / xib, make sure that the File Owner is set to the appropriate class name and that the File Owner view output is connected to the appropriate view.

Update. I also see this behavior using an application based on the Nav-based application template, but it works with the View-based application template as expected.

I think that in the case of a navigation controller, the table view built into the view controller receives the event before the view controller. See UIView Link (highlighted by me):

View controllers themselves are descendants of the UIResponder class and are inserted into the responder chain between the managed root view and its supervision, which usually refers to a different kind of controller. If the view of the view manager does not handle the event , the view controller itself has the ability to process the event before passing this event in observing mode.

This means that the view has the first chance to handle the event, and if that happens, the view controller will not receive it.

It’s not clear what you are trying to accomplish, so I’m not sure which solution to offer.

+4
source share

If you are trying to reject the keyboard in a UITableViewController, a decent solution is to call resignFirstResponder on the tableView element didSelectRowAtIndexPath.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [myTextField resignFirstResponder]; // Rest of your actual didSelectRowAtIndexPath code ... } 
+5
source share

I just ran into the exact problem, as with the original publication. I ran into a problem by subclassing UITableView and overriding the "touchhesBegan" method. I also created a protocol so that UITableView can call a method in the UITableViewController, which I ultimately wanted to handle the "touchhesBegan" event.

Here is the title for the UITableView subtype:

 @protocol AGSTableViewDelegate; @interface AGSTableView : UITableView @property (nonatomic, weak) id<AGSTableViewDelegate> agsDelegate; @end @protocol AGSTableViewDelegate<NSObject> -(void)tableViewTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; @end 

And implementation:

 @implementation AGSTableView @synthesize agsDelegate; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; if (agsDelegate) [agsDelegate tableViewTouchesBegan:touches withEvent:event]; } @end 

And finally, the code snippets from the UITableViewController:

 @interface AGSWasteUpdateTableController ()<AGSTableViewDelegate> @end - (void)viewDidLoad { AGSTableView *tableView = (AGSTableView *)[self tableView]; tableView.agsDelegate = self; } -(void)tableViewTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [yourTextField resignFirstResponder]; } 

Hope this helps ...

+3
source share

You need to convey touch to the chain of respondents. We can do this by subclassing the UITableView and overriding touchBegan (and others, if necessary), and then pass the touch of the responder chain to the UITableViewController.

UITableViewTouch.h:

 #import <UIKit/UIKit.h> @interface UITableViewTouch : UITableView @end 

UITableViewTouch.m:

 #import "UITableViewTouch.h" @implementation UITableViewTouch - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; [[self nextResponder] touchesBegan:touches withEvent:event]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesCancelled:touches withEvent:event]; [[self nextResponder] touchesCancelled:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; [[self nextResponder] touchesEnded:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; [[self nextResponder] touchesMoved:touches withEvent:event]; } @end 
+1
source share

Quick version because I had this problem:

 import UIKit class BubbleTouchesTableView: UITableView { // Designed to bubble up touches from a UITableView override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) self.nextResponder()?.touchesBegan(touches, withEvent: event) } override func touchesCancelled(touches: NSSet, withEvent event: UIEvent) { super.touchesCancelled(touches, withEvent: event) self.nextResponder()?.touchesCancelled(touches, withEvent: event) } override func touchesEnded(touches: NSSet, withEvent event: UIEvent) { super.touchesEnded(touches, withEvent: event) self.nextResponder()?.touchesEnded(touches, withEvent: event) } override func touchesMoved(touches: NSSet, withEvent event: UIEvent) { super.touchesMoved(touches, withEvent: event) self.nextResponder()?.touchesMoved(touches, withEvent: event) } } 
+1
source share

All Articles