2011-01-11 92 views
16

我試過各種方法,這些都給了我警告。如userName = [NSString stringWithFormat:@"%@", [yournamefield stringValue]];這只是給了我如何將UITextField中的文本轉換爲NSString?

「的UITextField」的警告可能不會爲「-stringValue」

我怎麼做這個迴應?

userName = [NSString stringWithFormat:@"%@", yournamefield.text]; 
+0

http://developer.apple.com/library/ios/#documentation/uikit/ reference/UITextField_Class/Reference/UITextField.html#// apple_ref/doc/uid/TP40006888 – filipe 2011-01-11 17:07:24

+0

`-stringValue`是`NSTextField`的一種方法 – NSGod 2011-01-11 18:45:28

回答

39

使用text財產

NSString *name = yourNameField.text; 
+0

不!做**不**使用訪問器方法來明確定義公共頭中的屬性。 – PeyloW 2011-01-11 17:38:20

1

如何獲取文本字段中的文本。 這是一個屬性,任何屬性值可以這樣訪問 -

  • yournamefield.text
  • [yournamefield text]
12

使用的UITextFieldtext屬性:

NSString *userName = yourNameField.text;