Notice the semicolon ; after ..g:@""] == FALSE)
;. It should be ..g:@""] == FALSE) {...}
. BTW, You could also write : if(![mailIdentity isEqualToString:@""]) {...}
and if ([mailIdentity isEqualToString:@""]) {...}
if statement for MFMailComposer dosn`t work
-
31-05-2022 - |
Question
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.
Solution
OTHER TIPS
You definitely have semicolon problem here like @true said, but you may also consider that
isEqualToString:
may be tricky here if you compare it to empty string. You may also want to use:
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!");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow