사용자가 키보드를 닫을 때 textField에서 문자열 값을 가져 오려고합니다. 그러나, 그 값을 얻으려고 할 때마다 가비지가 생깁니다 (textField.text를 인쇄하려고하면 쓰레기가 나옵니다). 나는 무엇을 잘못 할 수 있 었는가?UITextField 텍스트 값이 가비지를 반환합니다.
(컨트롤이 잘 표시되고 텍스트 값을 넣을 수도 있습니다.)
여기 내 코드입니다 :
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
NSInteger currenttag = textField.tag;
NSLog(@"%d",textField.tag);
if (currenttag == 0) {
NSLog(@"%x %s",(unsigned int)textField.text,textField.text);
username = textField.text;
} else if (currenttag == 1) {
password = textField.text;
}
[textField resignFirstResponder];
return YES;
}
필드는 사용자 이름과 암호가있는 NSString *의 전무,하지만 난 단지 textField.text 할 보유한 NSStrings에 개최 이후, 괜찮을한다.
'username'과'password'는 필드라고 가정합니다. 그렇다면 제대로 유지해야합니다. – notnoop
약간의 코드를 보여줄 수 있습니까? 아니면 [textField.text retain]과 같은 것입니까? – futureelite7