访问现有的UITableViewCell

Don*_*onk 3 animation uitableview coordinates uiview ios

这是一个不同的问题,但我认为错误并没有错,所以我调整了标题以反映我真正想到的.

我正在制作一个动画,它在普通UITableViewCell的cell.imageView中获取一个图像的副本,并将其移动到屏幕底部的标签栏,以模拟将项目放入购物车.我可以复制图像并将副本作为窗口的子视图放置,但我无法弄清楚如何获得原始图像的绝对位置,因此我可以将它放在顶部作为动画的起点.

图像始终显示在屏幕顶部,就像放在0,0一样.

对不起这个问题的noobish性质,我敢肯定我错过了一些非常明显的东西.

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

UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
UIImageView *originalImgView = cell.imageView;
UIImageView *img = [[[UIImageView alloc] initWithImage: cell.imageView.image] autorelease];

NSLog(@"Original %@", originalImgView.bounds);  // Shows "Original (null)" at runtime.
NSLog(@"Window Points %@", [self.view.window convertPoint:originalImgView.frame.origin toView:nil]);
NSLog(@"Cell Points: %@", cell.bounds);  // Shows "Original (null)" at runtime.

[img setFrame:CGRectMake( originalImgView.bounds.origin.x, originalImgView.bounds.origin.y ,
        cell.imageView.image.size.width, cell.imageView.image.size.height)];

[self.view.window addSubview:img];

NSLog(@"Selected Cell: %@", cell); // Shows cell info at run time, works
Run Code Online (Sandbox Code Playgroud)

}

Don*_*onk 5

所以我这样做是错的.我正在制作一个具有相同内容的新单元格,而不是使用当前单元格.我通过在创建单元格时向其添加标签来修复此问题.

cell.tag = [indexPath row];

当[indexPath row] == 0时,除了给我一个问题.所以我给它添加了1000,这个问题就消失了.

cell.tag =(1000 + [indexPath row]);

然后我就换掉了这条线

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

UITableViewCell*cell =(UITableViewCell*)[self.tableView viewWithTag:(1000 + [indexPath row])];

现在我得到了对表视图中已经存在的实际单元格的引用,并且我得到了正确的帧值.