Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
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 {
NSLog(@"textFieldShouldReturn");
[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?
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
Seems like you're doing the right thing. Are you certain you have the delegate outlet set correctly? Maybe you should post the project?
 

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
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?
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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:

Code:
[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:

Code:
- (void) selectorChanged: (UISegmentedControl*) sender {
	
	switch (sender.selectedSegmentIndex) {
		case 0:
			// Do something for segment 0
			break;
		
		case 1:
			// Do something for segment 1
			break;
			
		default:
			// Handle a segment you weren't expecting	
			break;
	}
	
}
 

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Wow thanks you so much, that works perfectly now... I appericate your help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.