I know you see this question posted a lot, but I've yet to find an answer that explain the entire process of how this needs to be done. I've written the following code and it just doesn't work, at all.
I have a UIScrollView that gets populated with a few labels and text fields programatically. The input is numeric only so there is no "Done" button on the keyboard to resign things that way. I need it to be done when the user touches anywhere outside of the UITextField that just had focus. So I setup a "backgroundTouched" method that is called on the Touch Down event on my Scroll View. Here is what I have:
-(void)viewDidLoad Method
Code:
for (int i = 0; i < 14; i++)
{
int ii = i + 1;
textFieldCollection = [[UITextField alloc] initWithFrame:CGRectMake(193, textFieldOffset, 64, 31)];
textFieldCollection.placeholder = @"score";
textFieldCollection.backgroundColor = [UIColor whiteColor];
textFieldCollection.borderStyle = UITextBorderStyleBezel;
textFieldCollection.textAlignment = UITextAlignmentCenter;
textFieldCollection.keyboardType = UIKeyboardTypeNumberPad;
textFieldCollection.tag = ii;
[textFieldCollection addTarget:self action:@selector(backgroundTouched:) forControlEvents:UIControlEventEditingDidEnd];
textFieldOffset += 38;
[self.scrollView addSubview:textFieldCollection];
[textFieldCollection release];
}
-(IBAction)backgroundTouched Method
Code:
- (IBAction)backgroundTouched:(id)sender
{
[sender resignFirstResponder];
}
Am I missing something obvious or is this just something that is very tedious to do?
Thanks in advance!