问题
I want to present a popover. Currently I can retrieve the frame of the whole cell (as described here). Is it possible to get the frame of the accessory (UITableViewCellAccessoryType
)?
I want to retrieve the value in accessoryButtonTappedForRowWithIndexPath
or didSelectRowAtIndexPath
.
回答1:
in didSelectRowAtIndexPath
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect accessoryRect = cell.accessoryView.frame;
回答2:
The best I can come up with is to calculate the frame with fixed sizes. First you get the cell's frame with rectForRowAtIndexPath
. Than you calculate the accessoryType
frame. In my case I can give C# code, but you can translate it to Objective-C easily or roll your own solution:
int detailDisclosureSize = 24;
RectangleF accessoryPosition = new RectangleF(cellPosition.X + cellPosition.Width - detailDisclosureSize * 2.45f, cellPosition.Y + cellPosition.Height/2 - detailDisclosureSize/2, detailDisclosureSize, detailDisclosureSize);
cellPosition
is the result from rectForRowAtIndexPath
. Now you can translate it to the real coordinates with convertRect:toView:
.
But the solution won't work if a new screen size comes out. Since there is currently no other solution I'll go with this or the whole cell size.
来源:https://stackoverflow.com/questions/26509740/get-frame-for-uitableviewcellaccessorytype