2012-08-07 251 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 
    }