objective-C UITextField Positioning

Associate
Joined
25 Feb 2007
Posts
905
Location
Midlands
I have a login screen in my app on which I hide UITextFields depending on whether it's the first time the user has logged in.

I have 5 fields in total, and the middle 3 get hidden. In this instance, I want to move the bottom field up so that it sits where the second used to (i.e. underneath the first).

I'd been doing this by setting the center attribute of the bottom field to be the same as the second in ViewDidLoad - this worked fine but has suddenly stopped and I'm not sure what I've done (if anything) to cause this.

Any ideas, or better ways to do this?
 
At first I had secondTextField.center = firstTextField.center, which worked fine, but for some reason then stopped working.

I've also tried the CGRectMake method, which also didn't work, so I logged the values that we're being passed (as in your example) and they all returned zero??

I'll try the frame = frame version you mention at the bottom - they are both exactly the same dimensions. I literally need to move it up x number of pixels!
 
Yeah it's all connected, I know because I read the text input in another part of my code, I also hide the same firstTextField after I move the secondTextField to it's position so I know that bits working...strange
 
I'm confused as it suddenly stopped working, after being fine for some time!

I've NSLogged the center values of both UITextFields and they are both zero??

I tried setting the frame too, that didn't work.

Where/how do I call setNeedsDisplay?

I'm sure I'm missing something simple somewhere, it's like I don't have them hooked up correctly, but I do as I can read the text entered by the user...
 
Here's my code:

Code:
if(sqlite3_step(statement) == SQLITE_ROW){
                
                aUserIsAlreadyRegistered = true;
                
                self.password.center = CGPointMake(self.password.center.x, self.surname.center.y);
                NSLog(@"New Password Center: %f, Surname Center: %f",self.password.center.y, self.surname.center.y);
                self.surname.hidden = true;
                self.dateofbirth.hidden = true;
                self.postcode.hidden = true;

A query runs to check for the existence of a 'users' table, and if there is one, the user has logged in before (I know that sounds presumptuous but that would be correct for my application - irrelevant anyway)

So if the users table does exist, set a flag to say so, and they set up the view. So I change the password textfield to move to the location of the surname textfield, and then hide the fields that aren't required.

At first I thought that it was to do with the If, but the fields get hidden correctly! The NSLog is where I'm seeing zero returned for both!
 
OK, I've tried creating a CGRect (from static values).

I've set this as the frame of the UITextField, but it still doesn't move.

The strange thing is, logging the new values of the UITextField frame returns the correct figures!

Really stumped on this one!
 
Back
Top Bottom