Hi Everyone,
I am having a problem that I cannot seem to fix. I have been looking all over the internet to find a solution but cannot find one.
I have a UITableView that I am using as data editor. In each cell I have 3 UITextFields and when you click on the Next/Previous buttons I would like it to scroll through the UITextFields and if you are pressing Next from the last UITextField in the cell the focus should move to the next cell.
All of this works fine if I do it just that way. The problem is that my UITableView is not completely displayed on the screen so if you click Next to a cell that is not on the screen then click Previous to the original cell, any changes you made are lost.
I therefore added code to the textFieldDidEndEditing function to copy the data to the data element in the NSArray. Now my data is not lost when the above takes place. The problem with this is now my Next/Previous function does not work as the UITextField is no longer able to become first responder.
I have run some tests and it comes down to having an assignment statement in either the same block with the resignFirstResponder and becomeFirstResponder code or in the textFieldDidEndEditing function. Below is the working and non working code.
I am really hoping someone can help me with this.
Working Code
Broken Code:
As you can see above. The only code that is different is the assignment statement after the resignFirstResponder.
Any help is very appreciated.
Thanks and Regards,
Terry
I am having a problem that I cannot seem to fix. I have been looking all over the internet to find a solution but cannot find one.
I have a UITableView that I am using as data editor. In each cell I have 3 UITextFields and when you click on the Next/Previous buttons I would like it to scroll through the UITextFields and if you are pressing Next from the last UITextField in the cell the focus should move to the next cell.
All of this works fine if I do it just that way. The problem is that my UITableView is not completely displayed on the screen so if you click Next to a cell that is not on the screen then click Previous to the original cell, any changes you made are lost.
I therefore added code to the textFieldDidEndEditing function to copy the data to the data element in the NSArray. Now my data is not lost when the above takes place. The problem with this is now my Next/Previous function does not work as the UITextField is no longer able to become first responder.
I have run some tests and it comes down to having an assignment statement in either the same block with the resignFirstResponder and becomeFirstResponder code or in the textFieldDidEndEditing function. Below is the working and non working code.
I am really hoping someone can help me with this.
Working Code
Code:
- (void) nextField:(id)sender
{
NSLog(@"Next Field");
UITableViewCell *cellTmp = [[self tableView] cellForRowAtIndexPath:self.selectedIndexPath];
GradingSchemeCell1 *cell = (GradingSchemeCell1 *)cellTmp;
GradingScheme *selectedObject = [self.fetchedResultsController objectAtIndexPath:cell.indexPath];
NSLog(@"Letter Grade: %@, GPA: %@",[selectedObject letterGrade], cell.cellField1.text);
int selectedSection = self.selectedIndexPath.section;
if (cell == nil)
{
return;
}
if ([cell.cellField1 isFirstResponder])
{
[cell.cellField1 resignFirstResponder];
[cell.minGrade becomeFirstResponder];
[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
...
}
Code:
- (void) nextField:(id)sender
{
NSLog(@"Next Field");
UITableViewCell *cellTmp = [[self tableView] cellForRowAtIndexPath:self.selectedIndexPath];
GradingSchemeCell1 *cell = (GradingSchemeCell1 *)cellTmp;
GradingScheme *selectedObject = [self.fetchedResultsController objectAtIndexPath:cell.indexPath];
NSLog(@"Letter Grade: %@, GPA: %@",[selectedObject letterGrade], cell.cellField1.text);
int selectedSection = self.selectedIndexPath.section;
if (cell == nil)
{
return;
}
if ([cell.cellField1 isFirstResponder])
{
[cell.cellField1 resignFirstResponder];
[COLOR="Red"]selectedObject.gPA = [[NSDecimalNumber alloc] initWithString:cell.cellField1.text];[/COLOR]
[cell.minGrade becomeFirstResponder];
[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
...
}
Any help is very appreciated.
Thanks and Regards,
Terry
Last edited by a moderator: