我有一個的UITextField,我創建它像這樣:UITextFeld比較失敗
firstnameField1 = [[UITextField alloc] initWithFrame:CGRectMake(85+320*4, 80, 150, 30)];
[firstnameField1 setBorderStyle:UITextBorderStyleRoundedRect];
[firstnameField1 setPlaceholder:@"Firstname"];
[firstnameField1 setDelegate:self];
[firstnameField1 setReturnKeyType:UIReturnKeyNext];
[scrollViewController addSubview:firstnameField1];
當用戶點擊我要檢查,如果文本字段的任何輸入到它,如果它的空返回鍵,用戶沒有輸入任何內容,我想返回並顯示一個標籤,告訴用戶該字段需要填充才能繼續,就像您在整個地方看到的一樣。
我做以下檢查:
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
//Check if the user has typed anything
if (textField.text == @"") {
//If not, show 'required' labels
[firstNameRequiredLbl1 setAlpha:1];
[surnameRequiredLbl1 setAlpha:1];
[firstNameRequiredLbl2 setAlpha:1];
[surnameRequiredLbl2 setAlpha:1];
return YES;
}
//Do all my other stuff, cut out for ease of reading, 100% doesn't affect this anyway
return YES;
}
我已經設置上的最後一個方法斷點,它跳到右邊過去,如果語句是否我輸入到該文本框或沒有。
任何想法?謝謝。