【发布时间】:2014-07-11 10:58:38
【问题描述】:
在我的UITableView 中,我添加了滑动UISwipeGestureRecognizer 到单元格。所以当我在任何单元格上滑动时,它会在该行上打开一个菜单。但是当我滚动表格视图时,由于单元格可重用性,菜单也会出现在表格下方的其他单元格上。但我只想在被刷过的行上显示菜单用户。
这是我的代码 -
-(StoreCell *)configureCellForIndexPath:(NSIndexPath *)indexPath table:(UITableView *)tablev{
UITableViewCell* cell;
static NSString *CellIdentifier = @"StoreCell";
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
StoreCell* stCell = (StoreCell *)cell;
stCell.delegate = self;
//configure my cell here
UISwipeGestureRecognizer* gestureR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];
[stCell addGestureRecognizer:gestureR];
UISwipeGestureRecognizer* gestureL = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipeFrom:)];
[gestureL setDirection:UISwipeGestureRecognizerDirectionLeft];
[stCell addGestureRecognizer:gestureL];
return stCell;
}
那么如何实现所需的行为,使菜单只出现在一行不被重复使用的单元格上。
任何帮助或建议将不胜感激。
【问题讨论】:
-
存储当前打开菜单的单元格的索引路径,如果正在绘制的单元格不属于该索引路径,则不显示菜单
-
另外你为什么要创建一个 UITableViewCell,然后在另一行初始化它,然后将它转换为不同的类?
-
我从其他有更多单元格的地方复制了这段代码,所以我在顶部定义了单元格,然后根据 indexpath 对其进行初始化。
-
@CW0007007 感谢您的回复,我已按照您的建议实施,但现在滚动后滑动单元格上不显示菜单?
-
我没有提出建议
标签: ios objective-c uitableview