3

我有一堆放置在 UIViewController1 中的水平 UITableView。我想找到被点击的 UITableViewCell 的位置,我想根据 UIViewController1 获得位置。所以这就是我在 didSelectRowAtIndexPath 中所做的:

MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];

                UIView *animatedView = [[UIView alloc] initWithFrame:cell.frame];
 [animatedView setFrame:[animatedView convertRect:animatedView.frame toView:self.newsRackController.view]];

但是,这似乎不能正确转换它。我究竟做错了什么?

4

2 回答 2

8

您需要从 UITableView 的视图转换 UITableViewCell 的 CGRect,然后将其再次转换为您的视图控制器视图。

但不是所有这些,也许你可以只使用 UITableView 的方法

- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath

获取此 CGRect 并将其转换为您的 UIViewController 的视图。

于 2012-09-05T00:28:39.497 回答
1

这是因为animatedView不属于任何父母,而您正在使用frameas bounds。您应该首先找到框架并animatedView相应地进行初始化。

MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];
CGRect animatedViewFrame = [tableView convertRect:cell.frame toView:self.newsRackController.view];
UIView *animatedView = [[UIView alloc] initWithFrame:animatedViewFrame];
于 2012-09-05T00:35:07.040 回答