0

我正在尝试在我的“游戏”中设置分享你的分数电子邮件,我有一个名为 totalCircles1 的值,它应该是一个整数,这是文件的导入代码:

#import "ShareViewController.h"
#import <MessageUI/MFMailComposeViewController.h>
#import "CircleTableViewController.h"

这是我用来发送电子邮件的代码:

    - (IBAction)emailShareButton:(id)sender {

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

    NSString *body = [NSString stringWithFormat:@"Hey, I just got a score of %d in the Circle Creator iPhone App! \n Check it out at: www.circlecreator.com ! ", totalCircles1];
    [self.emailSenderVC setMessageBody:body isHTML:NO];
    [self.emailSenderVC setToRecipients:[NSArray arrayWithObjects:@"-------@gmail.com", nil]];

    [self presentViewController:self.emailSenderVC animated:YES completion:nil];


}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result) {
        case MFMailComposeResultCancelled:
        case MFMailComposeResultSaved:
            break;

        case MFMailComposeResultSent:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Message sent" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            break;
        }

        default:
            break;
    }

    [self.emailSenderVC dismissViewControllerAnimated:YES completion:nil];
}

当我这样做时,我在引号“,totalCircles1];”旁边得到一个错误 说使用未声明的标识符“Total Circles 1”

我在这里或多或少地实现了它:

for(int i=1; i<=9; i++) {
    if((indexPath.row * 9  + i) <= totalCircles1) {
        NSString *key = [NSString stringWithFormat:@"%d@%d", i, indexPath.row];

        if([self.cache objectForKey:key]) {

这是有效的代码,但它是创建值的视图控制器:

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
totalCircles1 = [[defaults objectForKey:@"Total Circles"] intValue];

self.totalCirlesLabel.text = [NSString stringWithFormat:@"Total circles: %d", totalCircles1];
[self.tableView reloadData];
4

1 回答 1

0

你在哪里定义totalCircles1?如果您将其作为 @property 使用,则需要使用 self.totalCircles1 访问它

根据评论试试这个:

- (IBAction)emailShareButton:(id)sender {

// add these 2 lines to your code 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int totalCircles1 = [[defaults objectForKey:@"Total Circles"] intValue];


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

NSString *body = [NSString stringWithFormat:@"Hey, I just got a score of %d in the Circle Creator iPhone App! \n Check it out at: www.circlecreator.com ! ", totalCircles1];
[self.emailSenderVC setMessageBody:body isHTML:NO];
[self.emailSenderVC setToRecipients:[NSArray arrayWithObjects:@"-------@gmail.com", nil]];

[self presentViewController:self.emailSenderVC animated:YES completion:nil];

}
于 2013-11-11T17:02:24.913 回答