7

ユーザーが行を挿入および削除できるようにするために、オンに切り替えUITableViewています。setEditing:animated:編集がオンになっているときに、新しいinsert new item行をテーブルに追加してから、編集コントロールを通常のようにアニメーション化する必要があります。insert new itemフェードのようなものを使用して、新しい行がそれ自体でアニメーション化されることは望ましくありません。表示してから、既存のテーブルデータソースの行と同じようにスライドさせます。

ただし、現在のコードの結果として何が起こっているかを示します(クリックすると拡大表示されます)。

一番上の行は私が望むことをします-それは単にスライドして削除アイコンがフェードインします。それが消えると、削除アイコンはフェードアウトし、行は再び拡大します。

2番目の行は、自分でテーブルに追加した非データソース行です。表示されると、まったくアニメーション化されません。挿入アイコンと行が同時に表示され、スライドインしません。表示されなくなると、行は適切に拡張されますが、プラスアイコンも一緒にスライドします。アニメーションは行全体で発生し、プラスアイコンではなく、最初の行のように別々に行します。

これが私のコードの簡単な要約ですが、クラスファイルへのリンクを提供する方が良いかもしれないと思います。

ツールバーの編集ボタンを押すと、UIViewControllerメソッドを呼び出しますsetEditing:animated:。この方法では、次のことを行います...

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];

    // keep the table in the same editing mode
    [_table setEditing:editing animated:animated];

    if (editing) {

        [_table insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    } else {

        [_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }

}

これは、挿入のアニメーションが行われている場所です。[_table beginUpdate]とendUpdateですべてをラップし、行の挿入だけをラップしてみました。どちらも私が目指しているきれいなアニメーションを生成していないようです。

私が見逃しているかもしれないアイデアはありますか?コードファイル全体はここにあります:

https://github.com/ryancole/pound-client/blob/master/pound-client/controllers/ChannelListViewController.m#L106-L127

4

2 に答える 2

2

スーパーコールは、アニメーションを編集するためのスライドを実行するため、その後に何かを挿入すると、アニメーションに参加しません。あなたがしたいのは、その呼び出しの前に行を挿入し、後に行を削除することです。また、別のブール値を持つ行を追跡する必要があります。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    _amEditing = editing;

    if (editing) {

        [_table insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    } 

    [super setEditing:editing animated:animated];

    // keep the table in the same editing mode
    [self.view setEditing:editing animated:animated];

    if (!editing)
    {
        [_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    }


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _amEditing ? _channels.count + 1 : _channels.count;
}

アップデート:

最後から2番目の行のアイコンにはまだ奇妙なアニメーションがあります。これを回避するには、削除に遅延を追加できます。

    if (!editing)
    {
        [self performSelector:@selector(deleteLastRow) withObject:nil afterDelay:0.25];
    }

-(void) deleteLastRow
{
    [self.view deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_objects.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}
于 2013-01-11T16:16:21.383 に答える
1

コメントされているように[super setEditing:editing animated:animated]、行を挿入した後に呼び出す必要があります

 - (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    // remove this [super setEditing:editing animated:animated];

    // keep the table in the same editing mode
    [_table setEditing:editing animated:animated];

    if (editing) {

        [_table insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    } else {

        [_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }
  [super setEditing:editing animated:animated]; // add it here

}
于 2013-01-11T16:54:50.790 に答える