使用另一个View Controller中的Mutable Array

时间:2013-12-01 03:08:27

标签: ios nsmutablearray

我一直在环顾四周,找到了一些答案,但没有一个有效,我不知道我是否遗漏了什么。出于某种原因,punish.castigos以及playerView.players目前在代码中为零:

GameViewController.m中的

#import "SetPlayersViewController.h"
#import "SetPunishmentsViewController.h"

SetPlayersViewController *playersView = [[SetPlayersViewController alloc] init];
SetPunishmentViewController *Punish = [[SetPunishmentViewController alloc] init];
NSMutableArray *punishments = Punish.castigos;
NSMutableArray *playersOn = playersView.players;
int pickCard = arc4random() % numCards;
int playr = arc4random() % [playersOn count];//here is where i get EXC_ARITHMETIC(code=EXC = i386 DIV..)
int punsh = arc4random() % [punishments count];

在SetPlayersViewController.h中:

@interface SetPlayersViewController : UIViewController {
NSMutableArray *players;
}
@property (nonatomic,retain) NSMutableArray *players;

在SetPlayersViewController.m中:

@synthesize players;

//in view did load
players = [[NSMutableArray alloc] initWithObjects:@"A",@"B",nil];

1 个答案:

答案 0 :(得分:0)

这是因为UIViewController的延迟初始化。

仅在某人调用view属性后才会加载UIViewController的视图。 因此,只有在某个人调用了view属性之后才会调用viewDidLoad方法。

您应该在视图控制器f.e。

init方法中初始化数组
相关问题