0

値が null の場合にアラートを表示したい 値が null の場合は titleCategory があり、アラートを表示する必要があります

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];
}
4

3 に答える 3

1
if(test == nil)
{
    UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"" message:@"Test is null" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
    [alert show];
}
于 2012-08-07T08:32:33.607 に答える
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 
}
于 2012-08-07T08:46:54.420 に答える
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 
  }
于 2012-08-07T09:49:08.613 に答える