View Full Version : Keyboard Wont Resgin

Mar 29, 2009, 11:15 AM
Hey guys, I have googled this for hours and nothing seems to work, I have a UIView and in that I have 3 text fields and I just cant get the keyboard to dismiss when the return button is pressed. I have tried the whole:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;

I am putting it in the implementation file that I created with IB. I have connected the text fields delegates to the File Owner. Someone please help, am I putting that in the wrong spot? Do I need to call that somewhere? Should the "textField" variables be the name of my created text fields?

Mar 29, 2009, 11:23 AM
Seems like you're doing the right thing. Are you certain you have the delegate outlet set correctly? Maybe you should post the project?

Mar 29, 2009, 02:38 PM
Oh man, You are totally right my outlet deleagte for the Text Field was not set correctly, thanks man sometimes you just need someone to tell you to look over something again, thanks a lot.

I do have another question if you can help me... I am using a UISegment and I was trying to find the code so that one side of it is clicked one textfield is hidden and some text changes. I have it to where is does that if you reload the page but I want people to be able to just click the Segment control and it changes without having to press the back button then back to the same view. Can you help me?

Mar 29, 2009, 03:23 PM
Well, you just need to respond to changes in the UISegmentedControl.

So you set up an action in response to the "Value Changed" event in IB (like you would with any other control).

Or you can do this in code with something like:

[segmentedControl addTarget:self action:@selector(myActionForThisChange:) forControlEvents:UIControlEventValueChanged];

And then in that action you can check the selectedSegmentIndex of the UISegmentedControl to see which segment the user has selected.

Something like this for example:

- (void) selectorChanged: (UISegmentedControl*) sender {

switch (sender.selectedSegmentIndex) {
case 0:
// Do something for segment 0

case 1:
// Do something for segment 1

// Handle a segment you weren't expecting


Mar 29, 2009, 04:44 PM
Wow thanks you so much, that works perfectly now... I appericate your help!