Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

ios - NSArrayM insertObject:atIndex:]: object cannot be nil'

After a lot of search, and tries with some solutions on stackoverflow, i didn't find any answer which could solve my error : I have a UIViewcontroller, who's name is WorldViewController. In this UIViewcontroller, i had init some UIViews. I want to modificate some variables which depends of WorldViewController from some UIViews. And now that i put those lines :

WorldViewController * World = [[WorldViewController alloc] init];

it gives me :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

So, how to fix it ? Could it comes from the fact that WorldViewController is running ? And so, how to fix it ?

Edit : init method of my viewcontroller

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

        World1 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
        [World1 setBackgroundColor:[UIColor blackColor]];
        [self.view addSubview:World1];
        [World1 release];

        [self.view addSubview:ViewPig];
        [self.view addSubview:level1view];
        [self.view addSubview:level2view];
        [self.view addSubview:LoadView];
        [LoadView AnimPigLoadingWith:PigChargement];
        [LoadView AppearLabelLoading];
        [self.view addSubview:FondPauseGrise];
        [self.view addSubview:FondPause];
        [self.view addSubview:BoutonResume];
        [self.view addSubview:BoutonHome];
        [self performSelector:@selector(Chargement) withObject:nil afterDelay:0.5];
        [self performSelector:@selector(ViewAppears) withObject:nil afterDelay:5.5+2.5];
        [self performSelector:@selector(LabelPrevientDepartWithImage:) withObject:Trois afterDelay:9];
        [self performSelector:@selector(LabelPrevientDepartWithImage:) withObject:Deux afterDelay:10];
        [self performSelector:@selector(LabelPrevientDepartWithImage:) withObject:Un afterDelay:11];
        [self performSelector:@selector(LabelPrevientDepartWithImage:) withObject:Go afterDelay:12];
        [self performSelector:@selector(Lancement) withObject:nil afterDelay:(3)];
        [self performSelector:@selector(GestionMaps) withObject:nil afterDelay:(11+2)];
    }
    return self;
}

Thanks !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had a similar problem. My mistake was in not marking the view that I was trying to load as the initial view controller. My guess is that the there was no initial view controller to add to the array and hence the object was nil. I'm not sure how good this is at answering your question but it worked for me.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...