variable superview?

Discussion in 'iPhone/iPad Programming' started by ArtOfWarfare, Aug 25, 2008.

  1. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    Messages:
    6,245
    #1
    I'm trying to find the center of a view with:

    Code:
    currentY = activeSuperview.center.y;
    but I get this error:

    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.

    Code:
    activeSuperview = [textField superview];
     
  2. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #2
    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...
     
  3. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    Messages:
    6,245
    #3
    *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...

    Code:
    - (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)));
    Code:
    	}
    	
    	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?
     
  4. macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Messages:
    50
    Location:
    Right here.
    #4
    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
     
  5. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    Messages:
    6,245
    #5
    :)

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

Share This Page