我正在尝试使用tableView来显示联系人应用中的一些电话号码。 问题是,触发删除控件的表视图(UITableViewCellEditControl)右侧的小红色减号不会在我将其移出单元格后响应点击。 (我是通过使用willTrasistionToState和didTRansitionToState这样做的) 简而言之:我可以在我的tableViewCells中使用我的CellEditControl。它看起来像垃圾,但它的工作原理。 我也可以把控制器放在单元外面的左边。这样看起来很棒,但控制完全没用。
我想要我的蛋糕,也吃它! I.E.我希望控件显示在单元格之外,但功能齐全。 关于如何做到这一点的任何想法?
我摆弄了超载
-hitTest: withEvent:
和-pointInside: withEvent:
方法,但我无法让它发挥作用。
这是我最成功的尝试的来源,它根本没有成功。
我在我为此专门创建的UITableView-Subclass中这样做。
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
NSLog(@"%s", __FUNCTION__);
for (UIView *subView in self.subviews){
NSLog(@"testing subview: %@", NSStringFromClass(subView.class));
for (UIView *subsubView in subView.subviews) {
NSLog(@"testing subsubView: %@", NSStringFromClass(subsubView.class));
if ([NSStringFromClass(subsubView.class)isEqualToString:@"UITableViewCellEditControl"]) {
CGPoint subsubViewPoint = [subView convertPoint:point fromView:self];
if ([subsubView hitTest:subsubViewPoint withEvent:event]) {
NSLog(@"found it: %@", NSStringFromClass(subsubView.class));
return subsubView;
}
}
}
}
UIView *returnView = [super hitTest:point withEvent:event];
NSLog(@"returnView: %@", NSStringFromClass(returnView.class));
return returnView;
}
但至少它会找到最佳观点。
编辑:这是上述方法创建的日志输出。我知道很多文字,但它重复得很快。
2013-01-29 13:03:21.285 MaklerKid[2559:fb03] -[MKEditableTableView hitTest:withEvent:]
2013-01-29 13:03:21.287 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.287 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.288 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.289 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.290 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.291 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.291 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.292 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.293 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.294 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.294 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.295 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.296 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.296 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.297 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.297 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.298 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.299 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.299 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.300 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.300 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.301 MaklerKid[2559:fb03] found it: UITableViewCellEditControl
2013-01-29 13:03:21.302 MaklerKid[2559:fb03] -[MKEditableTableView hitTest:withEvent:]
2013-01-29 13:03:21.302 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.303 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.303 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.304 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.304 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.305 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.306 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.306 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.307 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.321 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.323 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.324 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.325 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.325 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.326 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.326 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.327 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.327 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.328 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.328 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.329 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.329 MaklerKid[2559:fb03] found it: UITableViewCellEditControl
2013-01-29 13:03:21.330 MaklerKid[2559:fb03] -[MKEditableTableView hitTest:withEvent:]
2013-01-29 13:03:21.341 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.342 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.343 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.343 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.344 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.344 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.345 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.345 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.346 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.346 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.347 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.347 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.348 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.362 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.363 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:21.363 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:21.364 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.365 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:21.365 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.366 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:21.366 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:21.367 MaklerKid[2559:fb03] found it: UITableViewCellEditControl
2013-01-29 13:03:22.061 MaklerKid[2559:fb03] -[MKEditableTableView hitTest:withEvent:]
2013-01-29 13:03:22.062 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.063 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.064 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.065 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.066 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.066 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.067 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.068 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.069 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.069 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.070 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.070 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.071 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.072 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.072 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.073 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.074 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.074 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.075 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.076 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.076 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.077 MaklerKid[2559:fb03] found it: UITableViewCellEditControl
2013-01-29 13:03:22.077 MaklerKid[2559:fb03] -[MKEditableTableView hitTest:withEvent:]
2013-01-29 13:03:22.078 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.079 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.079 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.080 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.080 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.081 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.081 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.082 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.083 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.083 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.084 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.084 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.085 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.085 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.086 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.087 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.087 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.088 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.088 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.089 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.089 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.090 MaklerKid[2559:fb03] found it: UITableViewCellEditControl
2013-01-29 13:03:22.091 MaklerKid[2559:fb03] -[MKEditableTableView hitTest:withEvent:]
2013-01-29 13:03:22.091 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.092 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.093 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.107 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.109 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.110 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.111 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.111 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.112 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.112 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.113 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.113 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.114 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.114 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.115 MaklerKid[2559:fb03] testing subview: MKEditableTableViewCell
2013-01-29 13:03:22.115 MaklerKid[2559:fb03] testing subsubView: UITableViewCellContentView
2013-01-29 13:03:22.128 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.129 MaklerKid[2559:fb03] testing subsubView: UITextField
2013-01-29 13:03:22.129 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.130 MaklerKid[2559:fb03] testing subsubView: UIView
2013-01-29 13:03:22.131 MaklerKid[2559:fb03] testing subsubView: UITableViewCellEditControl
2013-01-29 13:03:22.131 MaklerKid[2559:fb03] found it: UITableViewCellEditControl
下一页编辑: 因为我试图做什么似乎有些混乱(不介意现在的“为什么”)这里有一些图片要澄清:
图一:这有效,但看起来很糟糕:
图二:这看起来不错,但不起作用:
此外,我发现如果我点击以前的位置,控件仍然会收到触摸。即:如果在场景2中,我点击场景1中控件所在的位置(即在单元格内),将执行代码并显示DeleteControl。这对任何人都有意义吗?不是我,那是肯定的。
另一个编辑:
有些人提出的建议就像“重建Cell,所以有足够的空间来控制它”,但我不能这样做。期。 此外,有人建议我不应该“打破苹果设计模式”。 我在编辑模式下附加了我的联系人应用程序的快照。请注意,EditingControl是Cell的外部,就像在这张图片中一样(我删除了隐私的名称和号码):
图3:
请帮帮我,我完全迷失了。 提前谢谢!
答案 0 :(得分:1)