我有一个 UITableViewCell
子类,我添加了 UIView
到它的contentView
属性(property)。为了启用拖动该 subview ,我实现了 UIResponder
适当的方法:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self.superview];
if (currentLocation.x >= self.rootFrame.origin.x) {
return;
}
CGRect frame = self.frame;
frame.origin.x = currentLocation.x;
self.frame = frame;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.frame = self.rootFrame; // rootFrame is a copy of the initial frame
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesEnded:touches withEvent:event];
}
subview 可以毫无问题地拖动,但单元格也被选中,因此
-tableView:didSelectRowAtIndexPath:
正在被调用。如何防止在拖动 subview 时单元格被选中?
最佳答案
-[UITableViewCell setSelectionStyle: UITableViewCellSelectionStyleNone]
当然,
tableView:didSelectRowAtIndexPath:
仍将被调用 - 因此您可能希望有选择地忽略回调。
关于ios - 拖动 subview 时防止 UITableViewCell 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16338457/