2011-08-04 12 views
0

こんにちは、私はこのiPhone devの新人です。私はreloadRowsAtIndexPathsについて質問があります。ユーザーが1つのセルをタップすると、そのセルの下にあるボタンが展開され、もう一度タップするとセルが閉じます。これは一度に1つのセルを開閉するときにはうまく動作しますが、セル1をタップしたような順序でセルをタップすると、この奇妙なアニメーションが表示され、セル2がタップされてアニメーションが変わってしまいます。状況を十分に理解するためにはビデオを、低品質についてはごめんなさい。IPhone reloadRowsAtIndexPaths奇妙なアニメーション

http://www.youtube.com/watch?v=R28Rmti9wPQ

、ここでは、細胞

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: 
    (NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

selectedIndexPath = indexPath; 

//close the selected cell if it's open 
if(selectedIndex == indexPath.row) 
{ 
    selectedIndexPath = nil; 

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    selectedIndex = -1; 
    selectedIndexPath = indexPath; 
    return; 
} 

//this will reload the previously open cell to avoid it from being recycled 
if(selectedIndex >= 0) 
{ 
    NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0]; 
    selectedIndex = indexPath.row; 

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 

//now reload the selected cell 
if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath]) { 

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 

} 

をリロードするためのコードだと、ここでcellForRowAtIndexPathを作成するためのコードです。

if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath]) { 
    selectedIndex = indexPath.row; 
    static NSString *CustomCellIdentifier = @"CustomCell"; 
    CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier]; 
    if (customCell == nil) { 
     customCell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier] autorelease]; 
    } 
    customCell.locationLabelOutlet.text = [usgsFeeds objectAtIndex:[indexPath row]]; 
    customCell.dateLabelOutlet.text = [pubDateArr objectAtIndex:[indexPath row]]; 

    float thisMag; 
    thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue]; 
    customCell.magnitudeImageOutlet.image = [self imageForMagnitude:thisMag]; 
    [customCell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

    return customCell; 
} 

else{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     locationLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 225, 20)] autorelease]; 
     locationLabel.tag = kLocationLabelTag; 
     locationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0]; 
     locationLabel.backgroundColor = [UIColor clearColor]; 
     [cell.contentView addSubview:locationLabel]; 
//and all other views for the cell.... 

答えて

0

選択したセルと前に選択したセルの両方を再読み込みしてみてください。

これは私が自分のアプリで同様の問題を解決した方法です。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
if(selectedPath == indexPath) 
{ 
    return; 
} 

showNutritionInfo = NO; 

NSIndexPath *oldSelectedPath = selectedPath; 
selectedPath = indexPath; 
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, oldSelectedPath,nil] withRowAnimation:UITableViewRowAnimationFade]; } 
+0

すでに解決済みです。私はちょうど現在選択されているセルを実際にリロードする前に遅延を追加しました。 – Diffy

関連する問題