6

テーブル内の行を選択するときに、テーブルビューに新しい行を追加する必要があります。

次の方法を使用すると思いますか???

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

新しい行を追加するメソッド内に何を記述すればよいですか?

私を助けてください、

事前にシビンに感謝します。

4

4 に答える 4

13

行を動的に追加するときは、insertRowsAtIndexPathsを使用します。これは関数の例です

- (void) allServersFound {
    // called from delegate when bonjourservices has listings of machines:
    bonjourMachines = [bonjourService foundServers]; // NSArray of machine names;

    NSMutableArray *tempArray = [[NSMutableArray alloc] init];

    int i = 0;
    for (NSArray *count in bonjourMachines) {
        [tempArray addObject:[NSIndexPath indexPathForRow:i++ inSection:0]];
    }

    [[self tableView] beginUpdates];
    [[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone];
    [[self tableView] endUpdates];

    [tempArray release];
}
于 2010-02-05T18:44:06.783 に答える
2

配列からテーブルを埋める場合は、配列に要素を追加して呼び出すだけです。[myTable reloadData]

于 2009-10-26T08:19:27.477 に答える
1

データのリロードは素晴らしくシンプルですが、私が知る限りアニメーション化されません...

于 2010-06-21T14:41:52.793 に答える
0

ReloadData はテーブル ビューで行を追加できますが、行の追加時にアニメーションが必要な場合は、これらのコード行を使用する必要があります。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        NSMutableArray *tempArray = [[NSMutableArray alloc] init];
        [tempArray addObject:[NSIndexPath indexPathForRow:indexPath.row+1 inSection:0]];

        [mainArray insertObject:@"new row" atIndex:indexPath.row+1];

        [[self tableView] beginUpdates];
        [[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationFade];
        [[self tableView] endUpdates];

}
于 2012-10-08T07:08:08.493 に答える