2012-06-25 32 views

回答

3

使用來自NSStringintValueintegerValue

int answer = [myTextField.text intValue]; 

NSInteger answer = [myTextField.text integerValue]; 

您還可以使用floatValuedoubleValue浮點輸入。

1
NSInteger answer = [textField.text integerValue]; 

OR

int answer = [textField.text intValue]; 
+0

NSInteger的不是類;沒有「*」需要,我不認爲「int」是NSString上的一種方法。 –

+0

檢查http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html是否爲intValue。 返回接收者文本的整數值。 - (int)intValue – daidai

+0

「intValue」是NSString上的方法; 「int」,這就是你的答案所說的,不是。 –