title: IOS subtracting from programmatically made labels and steppers
body: <p>I'm making an ipad application for ticket sales, and i have a problem when i want to subtract..</p>
  
  <p>The UI is made like so:</p>
  
  <pre><code>  for(NSString *string in ticketArray){
  
      float y = 60*ticketCount+spaceFloat;
  
      //subView to contain one ticket
      UIView *ticketTypeView = [[UIView alloc]initWithFrame:CGRectMake(10, y, 1000, 60)];
      if(ticketCount%2){
      ticketTypeView.backgroundColor = [UIColor lightGrayColor];
      }
  
      [self.view addSubview:ticketTypeView];
  
      //label for ticket type name
      UILabel *ticketType = [[UILabel alloc]initWithFrame:CGRectMake(10, 3, 500, 50)];
      [ticketType setText:string];
      [ticketType setFont:[UIFont fontWithName:@"Helvetica neue" size:20.0]];
      [ticketTypeView addSubview:ticketType];
  
  
      //UIStepper for ticket amount
      UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(500, 16, 0, 0)];
      stepper.transform = CGAffineTransformMakeScale(1.2, 1.2);
      [stepper addTarget:self action:@selector(chanegestep:)    forControlEvents:UIControlEventValueChanged];
      stepper.maximumValue = 100;
      stepper.minimumValue = 0;
      [ticketTypeView addSubview:stepper];
  
      //label for price pr. ticket
      UILabel *pricePrTicket = [[UILabel alloc]initWithFrame:CGRectMake(620, 5, 100, 50)];
      [pricePrTicket setText:@"1000.50"];
      pricePrTicket.tag = kTagPriceTicket;
      [ticketTypeView addSubview:pricePrTicket];
  
      //totalPrice label
      UILabel *totalTypePrice = [[UILabel alloc]initWithFrame:CGRectMake(900, 5, 100, 50)];
      [totalTypePrice setText:@"0.00 Kr."];
      totalTypePrice.tag = kTagTotalTypePrice;
      [ticketTypeView addSubview:totalTypePrice];
  
      ticketCount++;
  }  
  </code></pre>
  
  <p>}</p>
  
  <p>my ValueChanged method:</p>
  
  <pre><code> - (IBAction) chanegestep:(UIStepper *)sender {
  double va = [sender value];
  NSLog(@"stepper pressed");
  
  
  //get the 2 labels for the price and for displaying price
  UILabel *ticketprice = (UILabel *)[sender.superview viewWithTag:kTagPriceTicket];
  UILabel *totalPrice = (UILabel *)[sender.superview viewWithTag:kTagTotalTypePrice];
  double price = [ticketprice.text doubleValue];
  
  
  
  //calc the total from that one ticet type
  double totalDisplayed = va*price;
  
  //add to the complete sales amount
  completeSalesAmount += totalDisplayed;
  
  
  NSLog(@"%.02f",completeSalesAmount);
  if(ticketprice){
      totalPrice.text = [[NSString alloc]initWithFormat:@"%.02fKr.",totalDisplayed];
  }
  
  //activate btnContinue
  if(completeSalesAmount!=0){
      [btnContinue setEnabled:YES];
  }
  
  
  
  
  //[ setText:[NSString stringWithFormat:@"%d", (int)va]];
  </code></pre>
  
  <p>}</p>
  
  <p>My problem: adding up the numbers works fine ofc, but when the "-" on the stepper is pressed i have to detect that somehow, and subtract the price for the given ticket from the totalSalesAmount..</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Regards, an up and coming IOS dev xD</p>
  
  <p>edit:</p>
  
  <p>the completedSalesAmount is calculated every time valueChanged is called..</p>
  
  <p>so lets say i have 2 ticket types, and there is 1 selected of each.</p>
  
  <p>ticket1 - price 10$ - amount 1, total 10$ (10*1)</p>
  
  <p>completeSalesAmount - 0 += (10*1) = 10$</p>
  
  <p>ticket2 - price 10$ - amount 1, total 10$ (10*1)</p>
  
  <p>completeSalesAmount - 10 += (10*1) = 20$</p>
  
  <p>now "-" is pressed on ticket1</p>
  
  <p>ticket1 - price 10$ - amount 0, total 0$ (10*0)</p>
  
  <p>completeSalesAmount += 0... </p>