2011-09-08 10 views
9

セクションの最初のセルにreloadRowsAtIndexPathsを呼び出すと、前のセクションが空で空のセルが空である場合、再ロードされたセルがどこにあるのか不思議なアニメーショングリッチが発生します( "UITableViewRowAnimationNone"私は一例に可能な限り簡素化しようとした...ダウン上記のセクションからUITableView reloadRowsAtIndexPathsグラフィカルグリッチ

をスライド:

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
if (section == 0) 
    return 1; 
else if (section == 1) 
    return 0; 
else if (section == 2) 
    return 3; 
return 0; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 
cell.textLabel.text = @"Text"; 

return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSArray *editedCell = [[NSArray alloc] initWithObjects:indexPath, nil]; 
//[self.tableView beginUpdates]; 
[self.tableView reloadRowsAtIndexPaths:editedCell withRowAnimation:UITableViewRowAnimationNone]; 
//[self.tableView endUpdates]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
return @"Section"; 
} 

実はあなたは最後の方法をコメントアウトすることができますが、それは問題のより良い理解を提供します。

答えて

12

セルに直接値を設定して、テーブルをリロードして不要なアニメーションを避けることができます。

優れたソリューションだ
- (void) setupCell:(UITableViewCell*)cell forIndexPath:(NSIndexPath*)indexPath { 
    cell.textLabel.text = @"Text"; // Or any value depending on index path 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [self setupCell:cell forIndexPath:indexPath]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // create cell 

    // Configure the cell... 
    [self setupCell:cell forIndexPath:indexPath]; 

    return cell; 
} 
+0

、とにかく、奇妙な行動からは、次のとおりです。また、明確なコードを作成し、コードの重複を避けるためには、別の方法(ので、我々は別の場所からそれを呼び出すことができるようになります)に、セルのセットアップを移動することができますreloadRowsAtIndexはバグを返しますか、それとも間違った方法で使用していましたか? – Fr4ncis

+0

@ Fr4ncis、わかりません。セルテーブルビューをリロードするには、ビュー階層から追加/削除したり、サブビューやその他のものを再構築したりする必要があります。これらの変換が内部的にどのように実装されるかによって異なります。 – Vladimir

+0

ありがとうございます。 – jalopezsuarez

関連する問題