0

我是 Objective 和 iPad 应用程序的新手。我试图显示一个我已经在单独的类/视图控制器中使用的数组。我试图访问的数组在“MainMenuScreen.m”中,我想在另一个名为“ScoresScreen.m”的类中使用该数组。我所有的代码都在工作,我只需要从另一个类中获取数组并插入我的代码。我尝试使用 Segue,但我在我的代码中遇到了这个错误,并且我卡住了。先感谢您


。H

#import <UIKit/UIKit.h>


@interface ScoresScreen : UIViewController<UITableViewDataSource, UITableViewDelegate>{
     NSMutableArray *scoresArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) NSMutableArray *scoresArray; //Added this line

@end

.m

#import "ScoresScreen.h"
#import "MainMenuScreen.h"

@interface ScoresScreen ()

@end

@implementation ScoresScreen
@synthesize scoresArray; //Added this line
NSMutableArray *TestScoresArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
   ...
....
....

.m

#import "MainMenuScreen.h"
#import "PlayGame.h"
#import "ImageTest.h"
#import "ScoresScreen.h"
@interface MainMenuScreen ()

@end

@implementation MainMenuScreen

//---------------------------------------------------------------------------------

//------------------------------------Variables------------------------------------

PlayGame *playGame;//PlayGameObject

NSMutableArray *gameDataArray;//Game Data Array (A array storying multable ImageTest Objects)

NSMutableArray *scoresArray;//<-------This need to go to view scores

//---------------------------------------------------------------------------------

//----------------------------------Constructors-----------------------------------

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    scoresArray = [[NSMutableArray alloc] init];

    [scoresArray addObject: [NSMutableArray arrayWithObjects:@"Bob",[NSNumber numberWithInt:134],nil]];//testData
    [scoresArray addObject: [NSMutableArray arrayWithObjects:@"Roger",[NSNumber numberWithInt:12],nil]];//testData
    [scoresArray addObject: [NSMutableArray arrayWithObjects:@"Ben",[NSNumber numberWithInt:34],nil]];//testData

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

//---------------------------------------------------------------------------------

//----------------------------------Add New Score----------------------------------
//a setter Method so Play Game can add the user name and score to the scoresArray
-(void)AddNewScore :(NSString *)userName :(int)score
{
    //adds user name and score to the array
    if (scoresArray != nil)
    {
        /*NSMutableArray *nameAndScore = [[NSMutableArray alloc] init];
        [nameAndScore addObject:userName];
        [nameAndScore addObject: [NSNumber numberWithInt:score]];//int needs to be converted before storing in an array
        [scoresArray addObject:nameAndScore];*/

        [scoresArray addObject: [NSMutableArray arrayWithObjects:userName,[NSNumber numberWithInt:score],nil]];


        for(NSMutableArray *m in scoresArray)
        {
            NSLog(@"%@%@", m[0],m[1]);//prints out the array in logs to make sure it is working
        }
    }
}




    //added this method
            - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
            {
               ScoresScreen *controller = [segue destinationViewController];
               controller.array = yourArray; //use of undeclared identifier 'yourarray'
//and this error "property 'array' not found on object of type 'ScoresScreen*'"
            }
    //This is where I get the error ^.

...请有人可以帮助我吗?谢谢

---------
4

1 回答 1

0

在 MainMenuScreen.m 文件中使用它

#import "MainMenuScreen.h"
#import "PlayGame.h"
#import "ImageTest.h"
#import "ScoreScreen.h"
于 2012-12-14T14:32:32.813 回答