我在编辑模式下滚动tableview时遇到问题。这是因为细胞的可重用性。我按照链接 - UITableView in Edit Mode - Delete Button Dissapears on Scroll
一无所获。
这是我的代码段 -
- (void)setEditing:(BOOL)editing
animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[tableView setEditing:editing animated:animated];
[tableView setAllowsMultipleSelectionDuringEditing:editing];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
[cell setEditingAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
cell.textLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row+1];
cell.detailTextLabel.text=@"";
cell.clipsToBounds = YES;
return cell;
}
那么任何人的建议或建议如何解决该问题?
谢谢。
答案 0 :(得分:3)
将-(void)setEditing:(BOOL)editing animated:(BOOL)animated
方法更改为:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
_myTV.allowsMultipleSelectionDuringEditing = NO;
[super setEditing:editing animated:animated];
if(editing) {
[_myTV setEditing:YES animated:YES];
} else {
[_myTV setEditing:NO animated:YES];
}
}
答案 1 :(得分:0)
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES; // return yes
}
现在运行你的程序,让我知道发生了什么?
修改
从here获取此演示。给出了很好的exlanation