1

新しい iOS7 でアプリをコンパイルすると、UITableView の編集モードに入ったときに問題が見つかりました。

赤いマイナス ボタンを押してテーブルの行を削除すると、この行が左にインデントされて [削除] ボタンが表示されます。ただし、このボタンが表示されると、セルのテキストが editAccesory と重なります (これは、テキストがセルの長さよりも長い場合にのみ発生します)。

オーバーラップを削除するにはどうすればよいですか?

編集:コメント内の画像

編集2:これはテーブル作成のコードです

- (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];
}

解決:

最後に、accessoryButton をデフォルトの状態にし、編集状態を使用して行を削除します。それが私が見つけた唯一の解決策です:(

おそらく、メソッド「willTransitionToState」は、人々が同様の問題を解決するのに役立つ可能性があります。

4

2 に答える 2

0

iOS 8.3 で同じ問題に直面したため、この質問に遭遇しました。セルのコンテンツとアクセサリ項目が重ならないと、編集アクセサリと削除確認を正しく表示できないようです。トランジション アニメーションを中断することなくこの問題を解決することは、非常に困難でした。;)

だからここに私の解決策があります(IBで自動レイアウト制約を使用していると仮定します):

  1. サブクラスを作成しUITableViewCell、IB のテーブル ビュー セルにリンクします。
  2. 右端のビューとセルのコンテンツ ビュー (余白まで) の間の水平方向の間隔を指定する autolayout 制約からアウトレットを追加します。
  3. willTransitionToState以下に示すようにandをオーバーライドしlayoutSubviewsます。

表のセルのサブクラス:

@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 に答える