アクションメソッドを使用してテキストフィールドから入力したデータに対話するにはどうすればよいですか?ボタン? たとえば、ユーザーはテキストフィールド賃金に9を入力し、時間フィールドには10を入力し、ボタンを押すと賃金(9)が計算され、時間(10)で計算され、テキストフィールドpayCheck、90に印刷されます。Objective-Cボタンを使ってUITextFieldsからデータ(文字列、整数、倍精度など)を取得する方法
0
A
答えて
0
NSString *text = [UITextField text];
を得ることができますしたい、例えばint型の値、
int intValue = [text intValue];
は、だからあなたのボタンをクリック扱う機能では、これらの値を取得し、
[UITextField setText:text];
を使用して別のテキストフィールドに割り当て
0
文字列にはcomponentSeperated by functionを使用できます。あなたがタイプにあなたを変換次にプロパティ「テキスト」
でテキストフィールドから値を取得することができますので、あなたの場合には、あなたは9と10を得ることができ、その後、あなたはそれを掛けることができますし、90
0
3つのテキストボックスを配置することができます.1つは賃金、1つは時間単位、もう1つは出力支払いチェックです。ユーザが賃金および/または時間を入力すると、賃金は給与チェックテキストボックスに示される。ここではコード化された例です:
#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
ここ.hファイルです
関連する問題
- 1. 文字列形式の可能性のある文字列倍精度または整数から整数へ
- 2. 2つの整数を使って倍精度整数の整数部分を表現する方法
- 3. 文字列に倍精度または整数がありますか?
- 4. Pointオブジェクトから倍精度の数値を取得する方法
- 5. JAVAが文字列に倍精度文字を追加する
- 6. 整数をATSの倍精度に変換する方法は?
- 7. コンソールアプリケーションの文字列/倍精度換算
- 8. 文字列から整数へのハッシュ関数の精度
- 9. 複数の数値を文字列から倍精度浮動小数点数に変換する方法
- 10. 文字列オブジェクトが整数、倍精度、ブール値、日付、または文字列であるかどうかを判断する方法は?
- 11. 倍精度/整数のベクトルテンプレート関数
- 12. Android文字列から倍精度への変換
- 13. なぜこの出力(整数と倍精度)が得られますか?
- 14. 列の値から浮動小数点/倍精度/整数を除きます
- 15. 倍精度乱数列
- 16. 文字列を共有設定から倍精度値に変換する
- 17. 浮動小数点/倍精度/整数値をHBaseでエンコードする方法は?
- 18. 数字と文字列を追加する(UITextFieldsのデータ)
- 19. 浮動小数点数を掛けて倍精度精度を維持する/取得する
- 20. n番目の倍精度数値を取得するには
- 21. 文字列の整数表現を取得する方法
- 22. 文字列と倍精度を含む外部テキストファイルでスキャナを使用する
- 23. 整数を暗黙的に倍精度に変換する方法は?
- 24. atoiを使用して、文字列から整数を取得する
- 25. 文字列番号の精度を取得する
- 26. 8バイトの倍精度文字列をuint64_tに変換
- 27. JavaScriptを使ってウェブサイトから文字列を取得する方法
- 28. JavaScriptパーセント計算から倍精度のように見える文字列を返す方法
- 29. C++で整数と倍精度の書式設定の行列
- 30. jsonの文字列winformからデータを取得する方法