2012-08-14 15 views
0

我想在三個不同的文本字段中乘以整數值。整數在文本字段中的乘法 - Xcode 4.4

@property (nonatomic,strong) IBOutlet UITextField *textField; 
@property (nonatomic,strong) IBOutlet UITextField *textField2; 
@property (nonatomic,strong) IBOutlet UITextField *textField3; 
@property (nonatomic,strong) IBOutlet UILabel *total; 

我試圖在UILabel中顯示產品。有人可以幫助實施嗎?非常感謝!

回答

0

以顯示的UILabel的產品,設置標籤的文本這樣(假設文本框都包含整數):

total.text = [NSString stringWithFormat: @"%i", (textField.text.intValue * textField2.text.intValue * textField3.text.intValue)]; 

,你可能想要把這個在一個單獨的方法,這樣你就可以從調用它在任何地方,比如用戶用新數字更新文本字段

+0

應該使用'float'而不是'int's作爲輸入值或答案可能包含小數。 – 2012-08-14 00:17:29

+0

帖子明確表示他們正在尋找乘以整數值。 – BJHStudios 2012-08-14 00:34:13