这是一个棘手的问题。我将简单说明我的程序目前可以做什么。只是它是一个充值系统
现在问题就出现了 - 当我尝试再次充值时,它应该在显示的数量之上添加,但它从头开始并加满初始设定值。
我希望有一种方法可以将它保存为全局变量,甚至可以从方法或循环中传递它直到程序结束。
这是.m文件
// button for confirming the selected top up amount & confirmation box
- (IBAction) confirmAmount:(id)sender{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Confirm Payment" message:@"Would you like to proceed with the payment?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil];
alertView.tag = 108;
[alertView show];
}
// method for toping up different amounts with segmentedcontrol
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
result =26.00;
for (int i = 0; i < 100; i++){
if (topUpamount.selectedSegmentIndex == 0)
{
result = result+ 20;
}
else if (topUpamount.selectedSegmentIndex == 1)
{
result = result + 40;
}
else if (topUpamount.selectedSegmentIndex == 2)
{
result = result + 50;
}
else if (topUpamount.selectedSegmentIndex == 3)
{
result = result + 60;
}
else if (topUpamount.selectedSegmentIndex == 4)
{
result = result + 80;
}
else
{
result = 0;
}
if (alertView.tag==108)
{
switch (buttonIndex) {
case 0:
break;
case 1:
currentBalance.text = [[NSString alloc] initWithFormat: @"%.2f",result]; break;
default:
break;
}
}