0

I have created Custom UITableViewCell and added one label to display product name and to choose quantity according to requirement I have created custom view with 2 scrollviews to select numbers from 00 to 99(each scrollview to display 0 to 9 numbers, so i have created labels and added to scrollview). Now user can scroll to set the prefered quantity for each product displayed in tableview.

My doubt is how to store the quantity selected by user for each product on tap of update quantity button.

Prasad
  • 1,904
  • 4
  • 19
  • 24
  • You need to handle tap event of quantity labels and assign the quanity to corresponding cell's datasource. – HRM Nov 21 '13 at 04:16

2 Answers2

1

For this, you have to implement scroll view delegate method scrollViewDidEndDragging. In this method you will get scroll scroll ended status and you can trace the current selected number.

But my suggestion is to use a custom number picker for this purpose. You can see some examples here.

https://www.cocoacontrols.com/controls/slnumberpickerview

http://code4app.net/ios/Dial-Controller/4f86e54806f6e71016000000

manujmv
  • 6,450
  • 1
  • 22
  • 35
0

This is simple don't worry about the entire table. Just check for one row. Rest will be done easily. I am assuming you have subclasses UITableView and UITableviewCell (However, this is not required but good practice to make it resuable).

First, have delegates for your UITableView :

-(void)didSelectQuantity:(NSUInteger)quantity forIndexPath:(NSIndexpath)indexPath.

Second, Encapsulate item information.

// Assume class NSProduct with property itemName,quantity,etc..
In your controller 
@property(nonatomic,retain)NSArray *productArray /*Array of NSProduct*/;

Third, In your UITableviewCell implement this logic but for scrollview (I would suggest to use a pickerview here or a UITableView to get selected value easily. Else you need your own logic here to figure out the selected value when scrolling ends)

- (void)valueSelected:(id)sender
{
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    if (indexPath != nil)
    {
       // call delegate.
    }
}

Apple has an excellent example illustrating how to solve such problems using pickerview inside a tableview. check here

Community
  • 1
  • 1
Kunal Balani
  • 4,739
  • 4
  • 36
  • 73