テーブル内の行を選択するときに、テーブルビューに新しい行を追加する必要があります。
次の方法を使用すると思いますか???
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
新しい行を追加するメソッド内に何を記述すればよいですか?
私を助けてください、
事前にシビンに感謝します。
行を動的に追加するときは、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];
}
配列からテーブルを埋める場合は、配列に要素を追加して呼び出すだけです。[myTable reloadData]
データのリロードは素晴らしくシンプルですが、私が知る限りアニメーション化されません...
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];
}