How to subclass UITableView?

I honestly don't know how to subclass UITableView. I am very confused and looking for any help I can get. How do I subclass a UITableView? The reason I need to do this is because I need the table to respond to the strokes in the background so that the keyboard can be hidden. I tried to search, but could not find anything. Any help is much appreciated!

+3
source share
2 answers

In most cases, you do not need a subclass UITableView, so you can avoid this. If you absolutely need to, create a subclass that inherits from UITableViewand overrides touch-related methods in the implementation:

// MyTableView.h

@interface MyTableView : UITableView {
}

@end

// MyTableView.m

@implementation MyTableView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
    [super touchesCancelled:touches withEvent:event];
}

@end
+10
source

Source: https://habr.com/ru/post/1758845/


All Articles