Iphone 在UITableViewCell中更改图像而不重新加载单元格

Iphone 在UITableViewCell中更改图像而不重新加载单元格,iphone,image,uitableview,Iphone,Image,Uitableview,我正在编写一个iPhone应用程序,其主要用户界面是UITableView。每个部分由两行组成,一行是标题,一行是正文。当用户单击标题时,我通过更改numberOfRowsInSection值删除第二行: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { cbwComponent *comp = [_componentController objectInL

我正在编写一个iPhone应用程序,其主要用户界面是UITableView。每个部分由两行组成,一行是标题,一行是正文。当用户单击标题时,我通过更改numberOfRowsInSection值删除第二行:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    cbwComponent *comp = [_componentController objectInListAtIndex:section];
    if([comp hasContentsView] && !comp.contentsHidden){
        return 2;
    }else
        return 1;
}
当用户选择标题时,我使用以下代码:

comp.contentsHidden = YES;
[self.tableView beginUpdates];
NSArray *deleteIndexPaths = [[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:1 inSection:indexPath.section], nil];
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
它的工作非常好,有一个很好的平滑褪色效果。问题是,我试图在标题单元格(第0行)中添加一个指示器,当单击该指示器时,该指示器会发生变化。要更改该图像,我必须刷新顶行和第二行,这会使过渡看起来很糟糕(嗯,没有那么平滑)。是否有方法在不刷新单元格的情况下更改UITableViewCell中的图像

谢谢

编辑:我想出来了!只要在对第二行进行更改之前重新加载第一行,就可以保持平滑过渡。它必须在[tableView BeginUpdate]的内部调用

[self.tableView beginUpdates]; 
[self.tableView reloadRowsAtIndexPaths:[[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:indexPath.section], nil] withRowAnimation:UITableViewRowAnimationNone]; 
... 
[self.tableView endUpdates];

成功了。

您还可以对tableview单元格进行子类化,并在其中实现视图转换,该转换可以从视图控制器调用。然后你就可以调用它,而无需重新加载单元格

[(YourCustomCell*)[tableView  cellForRowAtIndexPath:indexPathOfYourCell] fadeInIndicator];