0
Im新增Objective and iPad應用程序。我試圖顯示一個數組,我已經在一個單獨的類/視圖控制器中使用。試圖訪問的數組在「MainMenuScreen.m」中,我想在另一個名爲「ScoresScreen.m」的類中使用該數組。 所有我的代碼工作,我只需要從其他類的數組,並插入到我的code.I嘗試使用塞格但即時通訊我的代碼中得到這個錯誤,我卡住了。三江源提前嘗試使用陣列時發生錯誤 - 目標C
.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 ^.
...請有人可以幫助我嗎?由於
---------
感謝因德爾的快速反應:)我這樣做,但這些錯誤還在這裏 - 病患者編輯上述職位的代碼。 – tjose
@tjose編輯我的答案 –
是的,我確實改變了這種情況,當你說,但我仍然得到我在我的文章(在我的文章結尾)編輯的錯誤 – tjose