我将 3 个 UIView 堆叠在一起
UI表格视图
平面视图
根视图
TableView 位于顶部,rootView 位于底部。 (rootView 不可见,因为 TableView 在它上面)
我在 rootView 中实现了以下代码
/*code in rootView*/
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {}
期望当最顶层的视图(即 TableView)被触摸或移动时将调用这些函数,但相反,没有调用任何函数。
我还尝试将以下代码放入 TableView 中,以便调用 rootView 方法
/*code in TableView so that the rootView methods are called(TableView is the subview of rootView)*/
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
[self.superview touchesBegan:touches withEvent:event];
}
正如预期的那样,但问题是 TableView 委托喜欢
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
不被调用。
有什么方法可以确保 TableView 类中实现的 TableView 委托(didSelectRow:) 和 rootView 中的 TouchesBegan:,touchesMoved.. 函数也被相应调用?
即当我单击 TableCell 时,会调用 --> TableView 中的 (didSelectRow:atIndex) 函数和 -->rootView 中的 (touchesBegan 和 TouchesEnd) 方法。