views:

214

answers:

1

Hi All, I have a TableView with custom TableCellViews that has UILabels and UIButtons on it. when one of the buttons is taped I want to show a "tooltip" describing the text of the button.

Most everything is working except for when I try to convert the center coordinates of the UIButton to the coordinates of the rootView which is a UIView.

Here is the code: `- (void) fancyLabelButtonPressed: (UIButton *) button{

CGPoint btnPoint = button.center;   // x=200.5 y=27.5
CGPoint rootViewPoint = [button convertPoint:btnPoint toView:rootView];
//rootViewPoint -> x=390.5 y=197.5
CGPoint pointToUse = CGPointMake(btnPoint.x +20, rootViewPoint.y - 23); // Hack to get it close

` How can rootViewPoint.x=390.5 when I'm in portrait view?!!? By using the x from the button and the y from the rootViewPoint I get close to what it should be but it is just a hack.

Does anyone see what I'm doing wrong? or is there a better way?

Thanks,

Andrew

+1  A: 

This is because you are converting the point from the wrong view. The center property is actually in the coordinate system of the button's superview, whatever that is, so when you convert it to your rootView, you must convert it from there. So:

rootViewPoint = [[button superview] convertPoint:btnPoint toView:rootView];

That should give you what you are looking for.

Jason Coco
Works like a charm! Thanks Jason you ROCK! So does stackoverflow!Thanks again.
KingAndrew