Hey All,
so I have a table, each section has 2 cells with a text field in each. I create the cells like so:
I would like it so when the user is done entering values, they can hit next and have the focus shift to the next cell. From searching Google, I came up with this:
However, it never works! It always returns no. I've got the array of text fields, and I tried using that to set the next object in the array (based on the tags) to becomeFirstResponder. Still no dice.
Any ideas?
so I have a table, each section has 2 cells with a text field in each. I create the cells like so:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Fuel Surcharge Cell";
FuelSurchargeCell *cell = [self.fuelSurchargeTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[FuelSurchargeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// configure cell
NSMutableDictionary *currentDictionary = [self.fuelSurchargeArray objectAtIndex:indexPath.section];
NSMutableArray *descriptions = [currentDictionary objectForKey:@"descriptions"];
NSMutableArray *surcharges = [currentDictionary objectForKey:@"surcharges"];
cell.descriptionLabel.text = [descriptions objectAtIndex:indexPath.row];
if ([surcharges objectAtIndex:indexPath.row]) {
cell.inputField.text = [surcharges objectAtIndex:indexPath.row];
NSInteger tag = indexPath.section;
if (indexPath.row == 0) {
tag *= 2;
} else {
tag *= 2;
tag++;
}
cell.inputField.tag = tag;
cell.inputField.delegate = self;
cell.inputField.returnKeyType = UIReturnKeyNext;
[self.fscTextFields addObject:cell.inputField];
}
return cell;
}
I would like it so when the user is done entering values, they can hit next and have the focus shift to the next cell. From searching Google, I came up with this:
Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
FuelSurchargeCell *currentCell = (FuelSurchargeCell *)textField.superview.superview;
NSIndexPath *currentIndexPath = [self.fuelSurchargeTableView indexPathForCell:currentCell];
NSIndexPath *nextIndexPath;
if (currentIndexPath.row == 0) {
nextIndexPath = [NSIndexPath indexPathForRow:1 inSection:currentIndexPath.section];
} else {
nextIndexPath = [NSIndexPath indexPathForRow:0 inSection:(currentIndexPath.section + 1)];
}
[self.fuelSurchargeTableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
return [[self.fuelSurchargeTableView cellForRowAtIndexPath:nextIndexPath] becomeFirstResponder];
}
However, it never works! It always returns no. I've got the array of text fields, and I tried using that to set the next object in the array (based on the tags) to becomeFirstResponder. Still no dice.
Any ideas?