0

チケット販売用のiPadアプリを作っているのですが、引き算したい時に困ります..

UI は次のように作成されます。

  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++;
}  

}

私の ValueChanged メソッド:

 - (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]];

}

私の問題: 数値の合計は正常に機能しますが、ステッパーの「-」が押されたときに何らかの方法でそれを検出し、totalSalesAmount から指定されたチケットの価格を差し引く必要があります。

どんな助けでも大歓迎です。

よろしく、新進気鋭の IOS dev xD

編集:

completedSalesAmount は、valueChanged が呼び出されるたびに計算されます。

2 種類のチケットがあり、それぞれ 1 種類が選択されているとします。

ticket1 - 価格 10$ - 金額 1、合計 10$ (10*1)

完全な売上高 - 0 += (10*1) = 10$

ticket2 - 価格 10$ - 金額 1、合計 10$ (10*1)

completeSalesAmount - 10 += (10*1) = 20$

"-" が ticket1 で押されました

ticket1 - 価格 10$ - 金額 0、合計 0$ (10*0)

完全な売上高 += 0...

4

1 に答える 1