Im new to Objective and iPad apps. Im trying to display an array that Ive already used in a separate Class/View Controller. The array Im trying to access is in “MainMenuScreen.m” and I want to use that array in another class called “ScoresScreen.m”.
All my code is working, I just need to get the array from the other class and plug into my code.I tried using Segue but im getting this error in my code, and im stuck. Thankyou in advance
.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 ^.
…Please can someone help me? Thanks
---------
Use this in your MainMenuScreen.m file