PDA

View Full Version : variable superview?




ArtOfWarfare
Aug 25, 2008, 08:47 AM
I'm trying to find the center of a view with:

currentY = activeSuperview.center.y;

but I get this error:

error: request for member 'center' in something not a structure or union.

activeSuperview is declared as an id (I didn't know what else to declare it as,) becuase it'll change based on which UITextField is currently selected.

activeSuperview = [textField superview];



robbieduncan
Aug 25, 2008, 08:48 AM
It'll still be a UIView. So instead of id you can declare it as UIView *

Unless the text view doesn't have a super view of course...

ArtOfWarfare
Aug 25, 2008, 11:03 AM
*dope slap* thanks. I had tried calling it a UIView originally but it gave me an error (I can't remember what it was.) I had assumed it was because I tried calling it a UIView but the real issue was I left out the *.

Next issue...

I'm trying to move the superView (the idea is that the textField won't be obscured by the keyboard when it comes up.)

Here's my code along with the error that I get...

- (BOOL) textFieldShouldBeginEditing: (UITextField *) textField
{
activeSuperview = [textField superview];

if (textField.bounds.origin.y > 244)
{
activeSuperview.bounds.origin = CGPointMake (160, (activeSuperview.bounds.origin.y - (textField.bounds.origin.y - 244)));error: invalid lvalue in assignment
}

return YES;
}

It's supposed to move the superview of the textfield so that it isn't obscured by the keyboard when it's being edited. Is there an easier way to do it?

davedelong
Aug 25, 2008, 12:38 PM
What happens if you make a new CGRect instead of a CGPoint? Accessing the origin CGPoint directly like that seems a bit fishy to me.

Edit: and I think you're looking for the frame, not the bounds. IIRC, frame is relative to the superview, and bounds and local. So the origin of the bounds will always be 0,0.

Dave

ArtOfWarfare
Aug 26, 2008, 06:52 AM
What happens if you make a new CGRect instead of a CGPoint? Accessing the origin CGPoint directly like that seems a bit fishy to me.

Edit: and I think you're looking for the frame, not the bounds. IIRC, frame is relative to the superview, and bounds and local. So the origin of the bounds will always be 0,0.

Dave

:)

Thanks. Using the frame instead of bounds and a rect instead of a point worked perfectly.