0

I have a simple problem:

If i click on my mail button and there is no E-Mail address deposited i want the alertView to show up and i don`t want it to go to the Mail composer but it does.

The AlertView works but why does it goe to the MailComposer anyway?

Using X-Code, Objective C.

Here is the Code:

-(IBAction)sendMail {
  if ([mailIdentity isEqualToString:@""] == FALSE); {
   MFMailComposeViewController *mailController0 = [[MFMailComposeViewController    alloc]init];
   [mailController0 setMailComposeDelegate:self];
  NSString *email0 = mailIdentity;
   NSArray *emailArray0 = [[NSArray alloc] initWithObjects:email0, nil];
   [mailController0 setToRecipients:emailArray0];
[mailController0 setSubject:@"From my IPhone"];
[self presentViewController : mailController0 animated:YES completion:nil]; 
  }

if ([mailIdentity isEqualToString:@""] == TRUE) {
    UIAlertView *noMail = [[UIAlertView alloc] initWithTitle: @"noMail"
                                                        message: @"No E-Mail address"
                                                       delegate: nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [noMail show];
}

}

Thanks for the help.

4

2 回答 2

2

注意分号;之后..g:@""] == FALSE); . 应该是..g:@""] == FALSE) {...}。顺便说一句,你也可以写:if(![mailIdentity isEqualToString:@""]) {...}if ([mailIdentity isEqualToString:@""]) {...}

于 2013-06-09T09:54:05.900 回答
0

isEqualToString:就像@true 所说的那样,您肯定在这里遇到分号问题,但是如果您将其与空字符串进行比较,您也可能会认为这 可能会很棘手。您可能还想使用:

NSString *str; //if you change it to NSString *str = [[NSString alloc] init]; you will get diffetent if result
if([str isEqualToString:@""]) NSLog(@"this is string allocated but empty!");
if(!str) NSLog(@"this is not allocated NSString object!");
于 2013-06-09T10:19:28.947 回答