开发者

Make UITableViewCell into a UIView

开发者 https://www.devze.com 2023-03-14 00:41 出处:网络
I have a UITableView, and in the tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, I want to be able to access the frame that the selected cell is in.Here开发者_Stac

I have a UITableView, and in the tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, I want to be able to access the frame that the selected cell is in. Here开发者_StackOverflow is what I was trying:

UIView *cell = tableView.indexPathForSelectedRow;

UITableViewCell *cell = (UITableViewCell *)indexPath;

I want to be able to access the view that the selected cell is in.

thanks in advance.


To do this, use:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

than you can access all the info on cell as you would any other UIView

ie. cell.frame, cell.bound, etc.


Accessing the cell directly isn’t necessary—yes, you can get the cell and its frame via -cellForRowAtIndexPath:, but you’d then have to subtract the content offset of the UIScrollView (which UITableView subclasses from) to get the cell’s actual position within the boundaries of the table view. The best approach for this is the UITableView method -rectForRowAtIndexPath:.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号