gpt4 book ai didi

ios - moveRowAtIndexPath 方法后 tableView 标签错误

转载 作者:行者123 更新时间:2023-11-29 03:45:01 24 4
gpt4 key购买 nike

我有一个包含 7 个 TableView 的 View ,代表一周中的 7 天。每个 tableView 都使用 0 到 6 的标签进行初始化。我在单元格中创建了一个 longPressure 识别器来访问正确的 tableView:

- (IBAction)longPress:(UIGestureRecognizer *)sender {
self.clickedPoint = [sender locationInView:self.view];

// get most down subView user clicked
UIView *clickedSubView = [self.view hitTest:self.clickedPoint withEvent:nil];

if( [clickedSubView.superview isKindOfClass:[customCell class]] ) {

// get selected tableView
UITableView *selectedTableView = (UITableView*)clickedSubView.superview.superview;

NSLog(@"Selected tag: %d", selectedTableView.tag);
}
}

当我按下单元格时,标签会正确显示。问题是当我在 tableView 内移动行时。当我在 tableView 和 longPress 中执行 moveRowAtIndexPath: 时,我进行 moveRow 的 tableView 的标记始终获取另一个 tableView 的最后一个 longPress 的标记。

示例:

我在带有标签 2 的表中移动行。然后只需 longPress 带有标签 5 的表。然后返回到带有标签 2 的 longPress 表,但这次将记录 tag = 5(前一个)。如果长按带有标签 1 的表,则再次返回长按“标签 2 的表”(假设是),它会在应该是标签 2 的位置记录标签 1。

我读到,beginUpdates 会使标签丢失,因此需要重新加载。所以我尝试过这个:

// reload the tableView after moveRowAtIndexPath method
selectedTableView reloadData];

// also tried refresh the view that contains all the tableViews
[[self getWeekView] setNeedsDisplay];

// and also tried to set the tag again after moveRowAtIndexPath method
selectedTableView.tag = index;

没有任何效果。我还怀疑 clickedSubView 是否发生了问题,以及我是否获得了正确的 hitTest View ,但我用彩色边框对其进行了测试,它获得了正确的 View ,只是在 moveRowAtIndexPath 方法之后使用了错误的标签。

谢谢大家!

最佳答案

如果您正在使用表格 View 的自定义单元格,我想您正在使用,然后只需在自定义单元格上添加一个标签,或者如果您不想显示该标签,则将其隐藏。

当您将在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中加载数据的 tableview 单元格时,只需设置标签标签,这样就不会出现此标签问题。

关于ios - moveRowAtIndexPath 方法后 tableView 标签错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854026/

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