I am adding UITextFields to a UITableView in the cellForRowAtIndexPath method.
Once it’s all set up, I need to access them, for example I want to make the keyboard disappear when the background is selected like:
- (IBAction)touchBackground:(id)sender {
[textField resignFirstResponder];
}
and scroll to them when they are selected like:
- (void) textFieldDidBeginEditing:(UITextField *)textField {
UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
[settingsTable scrollToRowAtIndexPath:[settingsTable indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
However they only exist as temporary variables in the method, so i don’t know how to refer to them. I could declare them all beforehand in the header file, but I was hoping I wouldn’t have to, because this way to add more fields alter all I have to do is add to an array of cell titles.
You should add an instance variable with this propoerty:
Then You will assign the selected field to this instance variable
now in your method you can resign it