【问题标题】:how to do the cell editing in the table view without making any changes in the design of the cell?如何在不更改单元格设计的情况下在表格视图中进行单元格编辑?
【发布时间】:2013-05-01 08:43:38
【问题描述】:

我有一个应用程序,我在其中将tableview 保持为可编辑以拖放单元格。但是当我这样做时,cell 的设计正在发生变化,使得每个元素都居中,并且有一个三行的右显示按钮。我需要通过保持单元格的相同设计来做到这一点。没有任何披露按钮并保持单元格布局与不可编辑表格视图的情况相同。我在 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];

}

谁能帮我实现这个目标?

【问题讨论】:

  • This 可能有帮助
  • +1 为正确答案@MarOux

标签: iphone ios ipad


【解决方案1】:

试试这个:

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

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

然后在您的 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;
        }
      }
    }
  }
}

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

【讨论】:

    【解决方案2】:

    你应该对tableViewDatasource的这个方法返回NO:

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

    【讨论】:

    • 然后我无法编辑。我需要像以前一样拖动单元格。我的 pbm 是我不需要更改设计进行编辑。然后 didselect 也不起作用
    猜你喜欢
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    相关资源
    最近更新 更多