Вы можете поместить 3 текстовых поля вверх, одно для заработной платы, одно для часов и одно для выходного чека.Когда пользователь вводит данные о заработной плате и / или часах, оплата отображается в текстовом поле проверки оплаты.Вот кодированный пример:
Вот файл .h:
#import <UIKit/UIKit.h>
@class TestViewController;
@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
TestViewController *viewController;
UITextField *txtWage;
UITextField *txtHours;
UITextView *txtPay;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet TestViewController *viewController;
-(void)calculatePay;
@end
и файл .m:
#import "TestAppDelegate.h"
#import "TestViewController.h"
@implementation TestAppDelegate
@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// wage
txtWage = [[[UITextField alloc] initWithFrame:CGRectMake(10.0, 10.0, 50.0, 25.0)] autorelease];
txtWage.backgroundColor = [UIColor whiteColor];
txtWage.placeholder = @"wage";
[viewController.view addSubview:txtWage];
// hours
txtHours = [[[UITextField alloc] initWithFrame:CGRectMake(70.0, 10.0, 50.0, 25.0)] autorelease];
txtHours.backgroundColor = [UIColor whiteColor];
txtHours.placeholder = @"hours";
[viewController.view addSubview:txtHours];
// payCheck
txtPay = [[[UITextView alloc] initWithFrame:CGRectMake(150.0, 10.0, 50.0, 25.0)] autorelease];
txtPay.backgroundColor = [UIColor whiteColor];
txtPay.editable = NO;
[viewController.view addSubview:txtPay];
// list for changes to wage and hours
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(calculatePay)
name:UITextFieldTextDidChangeNotification
object:nil];
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
// have keyboard show up in wage box
[txtWage becomeFirstResponder];
return YES;
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[txtWage release];
[txtHours release];
[txtPay release];
[viewController release];
[window release];
[super dealloc];
}
#pragma mark -
#pragma mark Other Methods
-(void)calculatePay {
NSLog(@"calulating pay");
txtPay.text = @"";
if (txtWage.text.length > 0 && [txtWage.text intValue]>0
&& txtHours.text.length > 0 && [txtHours.text intValue]>0
)
{
int pay = [txtWage.text intValue] * [txtHours.text intValue];
txtPay.text = [[NSNumber numberWithInt:pay] stringValue];
}
}
@end