我最近一直在 Xcode 工作。我使用了一个带有 4 个文本框的表格视图,在一个按钮上单击我正在检查是否有任何文本框具有空值,如果没有将其保存在本地文件中。
代码如下
NSString *FName, *LName, *Email, *Pwd;
FName=registerFirstName.text;
LName=registerLastName.text;
Email=registerEmail.text;
Pwd=registerPassword.text;
BOOL fileexists=[[NSFileManager defaultManager]fileExistsAtPath:storePath];
if(!fileexists)
[storeManager createFileAtPath:storePath contents:nil attributes:nil];
if (FName !=NULL && LName != NULL && Email != NULL && Pwd != NULL && FName!=@"" && LName!=@"" && Email!=@"" && Pwd!=@"") {
UIAlertView *missingInfo=[[UIAlertView alloc]initWithTitle:@"Missing Details" message:@"All Fields Are Necessary" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[missingInfo show];
} else {
NSString *fullUserInfo;
fullUserInfo=[NSString stringWithFormat:@"First Name:\t%@\nLast Name:\t%@\nEmail ID:\t%@\nPassword:\t%@",FName,LName,Email,Pwd];
[fullUserInfo writeToFile:storePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
UIAlertView *test=[[UIAlertView alloc]initWithTitle:@"InfoSaved" message:fullUserInfo delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[test show];
}
当我在模拟器中运行它而不输入任何值时,它确实可以显示缺少字段的警报。但是当我在文本框中输入一些值然后删除它时,如果我单击完成以保存它,它会接受空值并将其存储到我不希望发生的情况。我的代码中的逻辑有什么问题,还是 xcode 中默认有其他函数来检查 null?