UITextField vs. UIPickerView in UITableViewCell?

620 Views Asked by At

What is the most suitable way to handle the product quantity for a catalog ordering iPad app. I am currently struggling trying to set up this values with UITextFields in UITableViewCells. The app displays the products in an alphabetical way depending on the first letter for the product. I have it set up using a SegmentedControl inside a UINavigationBar which refreshes the cells depending on the alphabet letter tapped, displaying only the products for that letter which is not the same across the board.

I posted a question yesterday to set up UITextFields for which using the UITextFieldDelegate was the answer I was more inclined to use. The problem that I still face with that option is that when I enter a number for the textField, it for some reason displays it on other cells. When I scroll up and down the list it keeps populating random cells with that value, and in some cases, removing the value from the cell that should actually have it.

Today, I am growing desperate and am trying to find options to handle those quantities. Probably using a UIPickerView, or some other type. Has anyone worked on something like an ordering catalog? Any shared info on how to approach this is more than greatly appreciated.

2

There are 2 best solutions below

0
On BEST ANSWER

I got it to work perfectly using a mutable dictionary to store the values using the shouldReturn method for the UITextFieldDelegate. From there, I would simply make it display the matching value from the dictionary to the productCode.

0
On

My first inclination is that you should implement -tableView:willDisplayCell:forRowAtIndexPath: and use the index path to determine the current quantity associated with that item. Not sure how your data is setup, but I would keep this information in an associated array.

Here's an example

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger *quantity = [quantities objectAtIndex:indexPath.row];
    cell.textField.text = [NSString stringWithFormat:@"%i", quantity];
}