Touches began in UITableViewController

后端 未结 5 1954
长发绾君心
长发绾君心 2021-01-17 22:38

I am defining this method in my UITableViewController subclass:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:to         


        
5条回答
  •  长发绾君心
    2021-01-17 22:38

    I just ran into the exact issue as the original posting. I got around the issue by creating a subclass of UITableView and overriding the "touchesBegan" method. I also created a protocol so the UITableView could call a method on the UITableViewController, which is ultimately where I wanted to handle the "touchesBegan" event.

    Here is the header for UITableView subtype:

    @protocol AGSTableViewDelegate;
    
    @interface AGSTableView : UITableView
    @property (nonatomic, weak) id agsDelegate;
    @end
    
    @protocol AGSTableViewDelegate
    -(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 fragments from UITableViewController:

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

    Hope this helps...

提交回复
热议问题