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]) {

これは機能するコードですが、値が作成されるのはView Controllerです。

 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 に答える