为什么我收到错误“预期标识符或”(“”

时间:2013-11-16 09:06:04

标签: ios objective-c

我正在制作一个共享操作视图但是在我的其他一个语句中我收到错误:“预期标识符或”(“”,我注释了错误发生在下面的地方:

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 0) {
        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {

            SLComposeViewController *tweetForm = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

            //Insert Total Circles Variable!

            [tweetForm setInitialText:@"I just got a score of %d total circles on Circle Creator for iOS, check it out and play for yourself at www.circlecreator.com"];

            [self presentViewController:tweetForm animated:YES completion:nil];

        } else {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure you have at least 1 twitter account set up & you are running at least iOS 6, if all fails contact our support email and we will be happy to help." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];

            [alertView show];

        }
    }else if (buttonIndex == 1) {
        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

            SLComposeViewController *facebookForm = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

            //Insert Total Circles Variable!

            [facebookForm setInitialText:@"I just got a score of %d total circles on Circle Creator for iOS, check it out and play for yourself at www.circlecreator.com"];

            [self presentViewController:facebookForm animated:YES completion:nil];

        } else {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure you have at least 1 Facebook account set up & you are running at least iOS 6, if all fails contact our support email and we will be happy to help." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];

            [alertView show];
        }

}else if (buttonIndex == 2) {

    self.emailSenderVC = [MFMailComposeViewController new];
      self.emailSenderVC.mailComposeDelegate = self;

       NSString *body = [NSString stringWithFormat:@"I just got a score of %d total circles on Circle Creator for iOS,\n check it out and play for yourself at www.circlecreator.com"];
       [self.emailSenderVC setMessageBody:body isHTML:NO];
      [self.emailSenderVC setToRecipients:[NSArray arrayWithObjects:@"", nil]];
       [self presentViewController:self.emailSenderVC animated:YES completion:nil];

}

这是我收到错误的地方,有人可以告诉我问题是什么,因为我花了几个小时试图解决它,我将非常感激:))

 //Here is where the error is happening!  
} else if (buttonIndex == 3) {
    MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
    viewController.body = @"I just got a score of %d total circles on Circle Creator for iOS,\n check it out and play for yourself at www.circlecreator.com";
    [self presentModalViewController:viewController animated:YES];

    }

2 个答案:

答案 0 :(得分:4)

替换

 //Here is where the error is happening!  
} else if (buttonIndex == 3) {
    MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
    viewController.body = @"I just got a score of %d total circles on Circle Creator for iOS,\n check it out and play for yourself at www.circlecreator.com";
    [self presentModalViewController:viewController animated:YES];

    }

使用:

else if (buttonIndex == 3) {
        MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
        viewController.body = @"I just got a score of %d total circles on Circle Creator for iOS,\n check it out and play for yourself at www.circlecreator.com";
        [self presentModalViewController:viewController animated:YES];

        }

}

在最后一个else子句之前还有一个额外的括号,它实际上应该在最后。

错误也在这里:

   NSString *body = [NSString stringWithFormat:@"I just got a score of %d total circles on Circle Creator for iOS,\n check it out and play for yourself at www.circlecreator.com"];

您正在使用占位符“%d”,但没有在那里给出值。

应该是这样的:

   NSString *body = [NSString stringWithFormat:@"I just got a score of %d total circles on Circle Creator for iOS,\n check it out and play for yourself at www.circlecreator.com", myInt];

感谢。

答案 1 :(得分:3)

错误在这些行中 - >

} else if (buttonIndex == 3) {

只需移除右括号,因为您已在上一行中关闭它。