如何在不改变单元格设计的情况下在表视图中进行单元格编辑?

时间:2021-09-01 22:19:04

I have an application in which I am keeping my tableview as editable to drag and drop cells. But when I am doing that the design of the cell is changing such that every element is become centered and there is a right disclosure button of three lines. I need to do this by keeping the same design of the cell.without having any disclosure button and keeping the cell layout same as it is in the case of noneditable table view.I am implemented the editing like this [tableview setEditing:YES animated:YES]; in the didload and implemented the delegates as

我有一个应用程序,我将我的tableview作为可编辑的来拖放单元格。但是当我这样做的时候,单元格的设计正在改变,每个元素都被居中,有一个三行显示按钮。我需要保持单元格的相同设计。没有任何显示按钮,并且保持单元格布局与不可编辑视图中的一样。我实现了这样的编辑[tableview setEditing:YES animated:YES];在didload中实现委托

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleNone;
}

- (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {

    NSInteger sourceRow = sourceIndexPath.row;
    NSInteger destRow = destinationIndexPath.row;
    id object = [array objectAtIndex:sourceRow];

    [array removeObjectAtIndex:sourceRow];
    [array insertObject:object atIndex:destRow];

}

Can anybody help me in acheiving this?

有人能帮我解决这个问题吗?

2 个解决方案

#1


2  

Give this a try:

给这一个尝试:

Add this method to your tableView delegate to prevent indentation:

将此方法添加到tableView委托中,以防止缩进:

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
  return  NO;
}

Then in your UITableViewCell subclass set all reordering views' alpha to 0:

然后在UITableViewCell子类中将所有重新排序视图的alpha设置为0:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
  [super setEditing:editing animated:animated];
  if (editing) {
    for (UIView * view in self.subviews) {
      NSLog(@"%@",view);
      if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound) {
        for (UIView *sv in view.subviews) {
          sv.alpha = 0.0f;
        }
      }
    }
  }
}

Please note that this is a hack and I'm not sure if apple would reject the app over this.

请注意这是一个hack,我不确定苹果是否会拒绝这个应用。

#2


0  

You should return NO to this method of the tableViewDatasource:

您应该向tableViewDatasource的此方法返回NO:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

#1


2  

Give this a try:

给这一个尝试:

Add this method to your tableView delegate to prevent indentation:

将此方法添加到tableView委托中,以防止缩进:

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
  return  NO;
}

Then in your UITableViewCell subclass set all reordering views' alpha to 0:

然后在UITableViewCell子类中将所有重新排序视图的alpha设置为0:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
  [super setEditing:editing animated:animated];
  if (editing) {
    for (UIView * view in self.subviews) {
      NSLog(@"%@",view);
      if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound) {
        for (UIView *sv in view.subviews) {
          sv.alpha = 0.0f;
        }
      }
    }
  }
}

Please note that this is a hack and I'm not sure if apple would reject the app over this.

请注意这是一个hack,我不确定苹果是否会拒绝这个应用。

#2


0  

You should return NO to this method of the tableViewDatasource:

您应该向tableViewDatasource的此方法返回NO:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath