2012-08-07 271 views
0

我想显示警报时,值是零,我有titleCategory如果有null值,那么它应该自动显示警告如何显示警报时,值是空

NSString*test=titleCategory; 
if ([titleCategory isEqualToString:nil]) 
{ 
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Select Category " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 
else 
{ 
    FirstViewController*targetController=[[FirstViewController alloc]init]; 
    [self.navigationController pushViewController:targetController animated:YES]; 
} 
+0

变化'如果([titleCategory isEqualToSt如果([标题类别长度] = 0)' – iNoob 2012-08-07 08:38:11

+0

iNoob感谢它的工作如果我有那里的价值,我希望他们中的任何一个是长度然后显示警报 – user1567956 2012-08-07 08:41:10

+0

你在哪里设置'titleCategory '变量? – rckoenes 2012-08-07 08:41:19

回答

1
if(test == nil) 
{ 
    UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"" message:@"Test is null" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
    [alert show]; 
} 
+0

我使用上面添加的代码chekc在nslog中titleCategory show null – user1567956 2012-08-07 08:37:01

0

这样做:

if (!(titleCategory.length > 0) || titleCategory == nil) 
{ 
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Select Category " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 
else 
{ 
    FirstViewController*targetController=[[FirstViewController alloc]init]; 
    [self.navigationController pushViewController:targetController animated:YES]; 
    [targetController release]; // if not ARC 
} 
0

请使用此代码:

if([titleCategory.text isKindOfClass:[NSNull class]]){ 
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Select 
    Category " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
    } 
    else{ 
    FirstViewController*targetController=[[FirstViewController alloc]init]; 
    [self.navigationController pushViewController:targetController animated:YES]; 
    [targetController release]; // if not ARC 
    }