UIAlertView在iPhone应用程序中无法正确显示

时间:2012-05-16 05:07:55

标签: iphone xcode

在iphone应用程序中我使用alertview来检查文本框值是否为空然后它应该显示警告其他明智的移动到下一个屏幕但是当我也再次输入值时警报视图显示我不知道是什么问题

如果我也输入值,那么它总是显示为真是

   -(IBAction)buttonClick{
   if (monthTextField.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}


 else if (motionSicknessTextField.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}


else if (prescriptionTextField.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}


else if (otherMeansTextField.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}
else if (cereniaTextField.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}
else if (costToClientTextField.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}

else if (clinicMarkup.text=@"") {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enter values first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];


}
   else{    

GraphsViewController*targetController=[[GraphsViewController alloc]init];

NSString*dogswithMotionSickness=motionSicknessTextField.text;
NSString*valueOne=cereniaTextField.text;
NSString*valueTwo=prescriptionTextField.text;
NSString*valueThree=otherMeansTextField.text;
NSString*valueFour=overtheCounterTextField.text;
cerenia=cereniaTextField.text;


NSString*costToClient=costToClientTextField.text;
NSString*clinicalMarkup=clinicMarkup.text;
perMonth=monthTextField.text;


targetController.perMonth=perMonth;
targetController.dogswithMotionSickness=dogswithMotionSickness;

targetController.valueOne=valueOne;
targetController.valueTwo=valueTwo;
targetController.valueThree=valueThree;
targetController.valueFour=valueFour;
targetController.cerenia=cerenia;
targetController.costToClient=costToClient;

targetController.clinicalMarkup=clinicalMarkup;

[self.navigationController pushViewController:targetController animated:YES];

  }}

3 个答案:

答案 0 :(得分:0)

如果要检查空字符串,请使用:

if([monthTextField.text isEqualToString:@""])

OR

if(monthTextField.text.length > 0)

答案 1 :(得分:0)

我在AppName-Prefix.pch文件中定义了这两个宏

#define IS_EMPTY_STRING(str) (!(str) || ![(str) isKindOfClass:NSString.class] || [(str) length] == 0)
#define IS_POPULATED_STRING(str) ((str) && [(str) isKindOfClass:NSString.class] && [(str) length] > 0)

这样我可以检查空字符串和nil字符串对象。

IS_EMPTY_STRING(myString);

答案 2 :(得分:0)

也可以使用

if ([motionSicknessTextField.text isEqualToString:@""] || [motionSicknessTextField.text isEqualTo:nil])  

它是带有nil的过滤器,也是textField

的空白对象或值