如果MFMailComposer的语句不起作用

时间:2013-06-09 09:49:42

标签: objective-c if-statement uialertview mfmailcomposer

我有一个简单的问题:

如果我点击我的邮件按钮并且没有存放电子邮件地址,我希望alertView显示,我不想让它去邮件作曲家,但确实如此。

AlertView可以工作,但为什么还要使用MailComposer呢?

使用X-Code,Objective C。

以下是代码:

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

}

感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

你绝对有像@true这样的分号问题,但你也可以考虑一下 如果将它与空字符串进行比较,isEqualToString:可能会很棘手。您可能还想使用:

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!");