老实说,我不知道如何子类化 UITableView.我非常困惑,正在寻找我能得到的任何帮助.如何对 UITableView 进行子类化"?我需要这样做的原因是因为我需要表格响应背景上的触摸,以便可以隐藏键盘.我试过谷歌搜索,但找不到任何东西.非常感谢任何帮助!
I honestly don't know how to subclass a UITableView. I'm super confused and looking for whatever help I can get. How do I go about "subclassing" a UITableView? Reason I need to do it is because I need for the table to respond to touches on the background so that keyboards can be hidden. I've tried googling but couldn't find anything. Any help is extremely appreciated!
大多数时候你不需要子类化 UITableView
,所以先看看你是否可以避免这样做.如果您绝对必须,创建一个继承自 UITableView
的子类,并在实现中覆盖与触摸相关的方法:
Most of the time you shouldn't need to subclass UITableView
, so see if you can avoid doing so first. If you absolutely have to, create a subclass that inherits from UITableView
and override the 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
这篇关于如何继承 UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!