gpt4 book ai didi

iphone - 如何在不显示重新排序控件的情况下重新排序 uitableviewcell?

转载 作者:行者123 更新时间:2023-12-03 18:55:37 25 4
gpt4 key购买 nike

我正在为我的 ipad 应用程序使用 spliviewcontroller。我还对 spliview 左侧的 uitableview 实现了重新排序。我想要实现的是用户可以对 tableCell 重新排序,但不需要触摸三个白条。用户应该能够触摸单元格上的任何位置并重新排序。可能吗?

最佳答案

下面的类将隐藏重新排序控件并使整个 UITableViewCell 可触摸以进行重新排序。此外,它还负责将内容 View 的大小重新调整为其原始大小,这对于自动布局非常重要。

@interface UITableViewCellReorder : UITableViewCell
{
__weak UIView *_reorderControl;
}

@implementation UITableViewCellReorder

#define REORDER_CONTROL_CLASSNAME @"UITableViewCellReorderControl"

/*
Override layoutSubviews to resize the content view's frame to its original size which is the size
of the cell. This is important for autolayout!
Do not call this method on super, as we don't need any further layouting wihtin the cell itself.
*/

- (void)layoutSubviews
{
self.contentView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self setAndHideReorderControl];
}

/*
Find the reorder control, store a reference and hide it.
*/

- (void) setAndHideReorderControl
{
if (_reorderControl)
return;

// > iOS 7
for(UIView* view in [[self.subviews objectAtIndex:0] subviews])
if([[[view class] description] isEqualToString:REORDER_CONTROL_CLASSNAME])
_reorderControl = view;

// < iOS 7
if (!_reorderControl)
for(UIView* view in self.subviews)
if([[[view class] description] isEqualToString:REORDER_CONTROL_CLASSNAME])
_reorderControl = view;

if (_reorderControl)
{
[_reorderControl setHidden:YES];
}
}


#pragma mark - Touch magic

/*
Just perform the specific selectors on the hidden reorder control to fire touch events on the control.
*/

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(beginTrackingWithTouch:withEvent:)])
{
UITouch * touch = [touches anyObject];
[_reorderControl performSelector:@selector(beginTrackingWithTouch:withEvent:) withObject:touch withObject:event];
}

[super touchesBegan:touches withEvent:event];
[self.nextResponder touchesBegan:touches withEvent:event];
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(continueTrackingWithTouch:withEvent:)])
{
UITouch * touch = [touches anyObject];
[_reorderControl performSelector:@selector(continueTrackingWithTouch:withEvent:) withObject:touch withObject:event];
}

[super touchesMoved:touches withEvent:event];
[self.nextResponder touchesMoved:touches withEvent:event];
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(cancelTrackingWithEvent:)])
{
[_reorderControl performSelector:@selector(cancelTrackingWithEvent:) withObject:event];
}

[super touchesCancelled:touches withEvent:event];
[self.nextResponder touchesCancelled:touches withEvent:event];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(endTrackingWithTouch:withEvent:)])
{
UITouch * touch = [touches anyObject];
[_reorderControl performSelector:@selector(endTrackingWithTouch:withEvent:) withObject:touch withObject:event];
}

[super touchesEnded:touches withEvent:event];
[self.nextResponder touchesEnded:touches withEvent:event];
}

@end

关于iphone - 如何在不显示重新排序控件的情况下重新排序 uitableviewcell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com