我一直在环顾四周,找到了一些答案,但没有一个有效,我不知道我是否遗漏了什么。出于某种原因,punish.castigos
以及playerView.players目前在代码中为零:
:
#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];
答案 0 :(得分:0)
这是因为UIViewController的延迟初始化。
仅在某人调用view属性后才会加载UIViewController
的视图。
因此,只有在某个人调用了view属性之后才会调用viewDidLoad
方法。
您应该在视图控制器f.e。
的init
方法中初始化数组