在uitableviewcell中更改自定义accessoryView?

can*_*boy 2 iphone objective-c uitableview

我试图在用户点击单元格后立即更改uitableviewcell的自定义accessoryView.我该怎么做?

为了记录,我正在使用Matt Gallagher的自定义表视图教程:

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

下载链接源:http://projectswithlove.com/projects/EasyCustomTable.zip


编辑

尝试了这个代码,但它只是改变了配件AFTER touch-up.也尝试了willSelectRowAtIndexPath,结果相同.

- (NSIndexPath *)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
    return indexPath;
 }
Run Code Online (Sandbox Code Playgroud)

编辑

通过使单元格的背景图像包含附件来解决问题.所以配件是"伪造"的,使它成为图像的一部分

ph.*_*dev 6

也许您可以尝试在willSelectRowAtIndexPath/didSelectRowAtIndexPath中重新加载单元格:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:NO];
 }
Run Code Online (Sandbox Code Playgroud)

另一个建议:didSelectRowAtIndexPath 返回void而不是NSIndexPath.