This is a tough question. I will simply state what my program can do at the moment. Simply it is a top up system
- shows the current balance (eg. $26.00)
- I can select a top up value from segmented control (eg. top up $20)
- current balance will be updated after selecting a top up. (current balance = $46)
Now here's the problem - when I try to top up again it should add on top of the amount shown but it starts over from scratch and tops up the initial set value.
I was hoping theres a method of saving it as a global variable or even pass it from a method or loop until program has ended.
this is the .m file
// 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;
}
}