【问题标题】:Three else-if statements [closed]三个 else-if 语句[关闭]
【发布时间】:2013-02-23 23:07:42
【问题描述】:

您好,我尝试使用 4 个按钮,每个按钮在按下时都有不同的警报。我遇到了一个问题,我有 3 个按钮,我决定添加一个“评价我的应用程序”按钮,但现在它不起作用,请帮助我。 (顺便说一下,错误是Expexted Exspression)(Org.=Organization(Fixed in App),Email-App 中的真实电子邮件,

#define TAG_Band 1
#define TAG_DEV 2
#define TAG_EDEV 3
#define TAG_RATE 4

@interface Org.ContactInfo () <MFMailComposeViewControllerDelegate>

@end

@implementation Org.ContactInfo:UIViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Contacts";

    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)ContactBand:(id)sender;{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact the Band" message:@"Contact the Org. or go to their website!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Visit the Org. Website",@"E-Mail The Org. President", @"E-Mail The Org. Treasurer",  nil];
    alert.tag = TAG_Band;
    [alert show];
}
-(IBAction)ContactDev:(id)sender;{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact Me" message:@"Contact Me on Features you would like me to consider! I will do my Best to look at all of the Suggestions!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Visit My Website",@"E-Mail Me!",  nil];
    alert.tag = TAG_DEV;
    [alert show];
}
-(IBAction)RateMyApp:(id)sender;{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rate My App" message:@"When Your Reviewing my App, Please remember that this app was at no cost to the Mighty Mustang Band." delegate:self cancelButtonTitle:@"Not Right Now" otherButtonTitles:@"Rate My App!!",  nil];
    alert.tag = TAG_RATE;
    [alert show];


}
-(IBAction)AppInfo:(id)sender;{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Version 1.0" message:@"More Updates Coming Soon. Please Feel Free to E-Mail me on features that you would like me to consider" delegate:self cancelButtonTitle:@"Not Right Now" otherButtonTitles:@"Email-Me",  nil];
    alert.tag = TAG_EDEV;
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == TAG_Band){


        if (buttonIndex==1){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://URL.org"]];

        }
        else if (buttonIndex==2){
            //Subject
            NSString *emailTitle = @"";
            //Recipients
            NSString *emailBody=@"Org. President";
            NSArray *toRecipients = [NSArray arrayWithObject:@"Person@Org.org"];

            MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
            mc.mailComposeDelegate = self;
            [mc setSubject:emailTitle];
            [mc setSubject:emailBody];
            [mc setToRecipients:toRecipients];

            [self presentViewController:mc animated:YES completion:NULL];

        }
        else if (buttonIndex==3){
            //Subject
            NSString *emailTitle = @"";
            //Recipients
            NSString *emailBody=@"Org. Treasurer, ";
            NSArray *toRecipients = [NSArray arrayWithObject:@"Person@Org.org"];

            MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
            mc.mailComposeDelegate = self;
            [mc setSubject:emailTitle];
            [mc setSubject:emailBody];
            [mc setToRecipients:toRecipients];

            [self presentViewController:mc animated:YES completion:NULL];

        }
    }
    else if (alertView.tag == TAG_DEV){
        if (buttonIndex==1){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://stepheniosdeveloper.wordpress.com"]];

        }
        else if (buttonIndex==2){
            NSString *emailTitle = @"";
            //Recipients
            NSString *emailBody=@"";
            NSArray *toRecipients = [NSArray arrayWithObject:@"Email@gmail.com"];

            MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
            mc.mailComposeDelegate = self;
            [mc setSubject:emailTitle];
            [mc setSubject:emailBody];
            [mc setToRecipients:toRecipients];

            [self presentViewController:mc animated:YES completion:NULL];

        }
    }
    else if (alertView.tag == TAG_EDEV);{
        if (buttonIndex==1){
            NSString *emailTitle = @"";
            //Recipients
            NSString *emailBody=@"";
            NSArray *toRecipients = [NSArray arrayWithObject:@"Email@gmail.com"];

            MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
            mc.mailComposeDelegate = self;
            [mc setSubject:emailTitle];
            [mc setSubject:emailBody];
            [mc setToRecipients:toRecipients];

            [self presentViewController:mc animated:YES completion:NULL];

        }
    }
    else if (alertView.tag == TAG_RATE);{         //Expected Expression
        if (buttonIndex==1){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/Org/id607257427?ls=1&mt=8"]];
        }
    }
}

在我在 (TAG_RATE) 上添加最后一个之前,它起作用了,但现在我不明白为什么它不再起作用了。请帮忙。

【问题讨论】:

  • 您对switch 声明有意见吗?
  • 你能帮我处理我的代码并用 switch 语句格式化它吗,我想过,但我不知道如何将它与我的警报和警报按钮操作一起使用。请将我的代码格式化到可以工作的地方。

标签: iphone objective-c compiler-errors


【解决方案1】:

您的代码中有一个错字:在最后两个else if 条件之后,您有额外的;

    else if (alertView.tag == TAG_EDEV)/*;*/{  // extra `;`
            //...
    }
    else if (alertView.tag == TAG_RATE)/*;*/{   // extra `;`       //Expected Expression
            // ...
    }

【讨论】:

  • 现在当我点击连接到 EDEV 标签的按钮时,它会打开 RATE 按钮连接到的链接。当我回到应用程序时,EDEV 标签的电子邮件视图已启动
  • 修复了它,实际上他们的错误以及那些错误确实很糟糕
  • 其实我还有一个问题。我已经在 iTunes 上连接了应用配置文件,如果您之前这样做过,您就会知道 App Store 中有一个用于查看链接的按钮。现在我还没有提交实际的二进制文件(所以它说“目前在美国商店中不可用”),但它正在等待上传。当应用程序被提交并且如果它被接受,URL 是否改变,我需要知道这个为我的应用程序标签评分。
  • 你需要使用断点来查看执行了哪一行代码。因为buttonIndex 可能不是您所期望的。我总是更喜欢使用按钮标题来代替
猜你喜欢
  • 2017-09-05
  • 2016-10-15
  • 1970-01-01
  • 2018-03-29
  • 2014-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多