我设置了 2 组 Objective-C 类(没有 xib 文件)
- AdultTicketCalculatorViewController
//.h 文件
#import <UIKit/UIKit.h>
@interface AdultTicketCalculatorViewController : UIViewController {
IBOutlet UITextField *Quantity;
IBOutlet UILabel *Pricelabel;
IBOutlet UILabel *TotalLabel;
}
-(IBAction)calculate;
-(IBAction)clear;
@end
//.m
#import "AdultTicketCalculatorViewController.h"
@interface AdultTicketCalculatorViewController ()
@end
@implementation AdultTicketCalculatorViewController
-(IBAction)calculate {
float x = ([Quantity.text floatValue]);
float c = x*15;
TotalLabel.text = [[NSString alloc] initWithFormat:@"$%.2f", c];
}
-(IBAction)clear {
Quantity.text =@"";
Pricelabel.text =@"$15.00";
TotalLabel.text =@"";
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[Quantity resignFirstResponder];
}
- AdultPayNowViewController
//。H
#import <UIKit/UIKit.h>
@interface AdultPayNowViewController : UIViewController {
IBOutlet UILabel *Quantity ,*Price ,*QuantitySpace ,*TotalSum ,*TotalSumSpace;
IBOutlet UIButton *ConfirmPurchase;
}
@end
//.m(我还没有实现任何东西)
我想从 AdultTicketCalculator 中获取一些用户输入和计算值,并以下列方式在 AdultPayNowViewController 中显示它们:
- UITextField 'Quantity' (AdultTicketCalculatorViewController) 出现在 UILabel 'QuantitySumSpace (AdultPayNowViewController)
- UILabel 'TotalLabel' (AdultTicketCalculatorViewController) 出现在 UILabel 'TotalSumSpace'