1

当我在新的iOS7中编译我的应用程序时,我在进入UITableView的编辑模式时发现了一个问题。

当我按下红色减号按钮删除表格的一行时,该行向左缩进以显示“删除”按钮。但是,当此按钮出现时,单元格的文本会与editingAccesory 重叠(仅当文本长于单元格的长度时才会发生这种情况)。

如何消除重叠?

编辑:评论中的图像

编辑2: Tis是创建表的代码

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{  
        return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        return [_tweetList count];
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *CellIdentifier = @"SessionDetailCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
        Tweet *tweet = [_tweetList objectAtIndex:indexPath.row];
        cell.textLabel.text = tweet.text;
        return cell;
 }

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (editingStyle == UITableViewCellEditingStyleDelete) {
                [tableView beginUpdates];

                Tweet *deletedTweet = [_tweetList objectAtIndex:indexPath.row];
                [_selectedSession removeTweetsObject:deletedTweet];
                [deletedTweet deleteEntity];
                _tweetList = [Tweet findAllSortedBy:@"index" ascending:YES withPredicate:[NSPredicate predicateWithFormat:@"session == %@",_selectedSession]];
                [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

                [tableView endUpdates];
        }
        [[NSManagedObjectContext defaultContext]saveToPersistentStoreWithCompletion:nil];
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
        selectedPath = indexPath;
        [self performSegueWithIdentifier:@"EditTweet" sender:self];
}

解决方案:

最后,我将附件按钮置于默认状态,而我只使用编辑状态来删除行。这是我找到的唯一解决方案:(

或许,“willTransitionToState”方法可以帮助人们解决类似的问题。

4

2 回答 2

1

您可以在编辑模式下隐藏或删除editingAccesory,因此那里没有重叠,

设置这个, 在此处输入图像描述

截屏:

在此处输入图像描述

于 2013-10-22T12:31:19.750 回答
0

我遇到了这个问题,因为在 iOS 8.3 中我遇到了同样的问题,如果没有单元格内容和附件项重叠,似乎无法正确显示编辑附件和删除确认。在不破坏过渡动画的情况下解决这个问题是一个很大的挑战。;)

所以这是我的解决方案(假设您在 IB 中使用自动布局约束):

  1. 创建一个UITableViewCell子类并将其链接到 IB 中的表格视图单元格。
  2. 从自动布局约束中添加一个出口,指定最右侧视图和单元格内容视图之间的水平间距(尾随到边距)。
  3. 覆盖willTransitionToStatelayoutSubviews如下所示。

表格单元子类:

@IBOutlet weak var horizontalSpaceConstraint: NSLayoutConstraint!

override func willTransitionToState(state: UITableViewCellStateMask) {
    if (state & UITableViewCellStateMask.ShowingDeleteConfirmationMask == UITableViewCellStateMask.ShowingDeleteConfirmationMask) {
        self.horizontalSpaceConstraint.constant = 49.0; // ugly, delete-confirmation width
    }
    super.willTransitionToState(state)
}

override func layoutSubviews() {
    if (!self.showingDeleteConfirmation) {
        self.horizontalSpaceConstraint.constant = 0.0;
    }
    super.layoutSubviews()
}

我不能使用didTransitionToState()layoutSubviews而是使用)来重置布局约束的原因是,从删除确认状态转换后,这个函数根本没有被调用(从 iOS 8.3 开始)。似乎Apple只处理了用户实际删除该行的情况,而不是删除确认关闭而不删除该行的情况。:(

于 2015-06-18T10:54:14.557 回答