经过大量搜索,并在stackoverflow上尝试了一些解决方案,我没有找到任何可以解决我的错误的答案:
我有一个 UIViewController,他的名字是 WorldViewController。在这个 UIViewcontroller 中,我初始化了一些 UIView。我想从一些 UIViews 修改一些取决于 WorldViewController 的变量。现在我把这些行:

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

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

那么,如何修复呢?难道是因为 WorldViewController 正在运行?那么,如何修复它?

编辑:我的 View Controller 的 init 方法
- (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;
}

谢谢 !

最佳答案

您没有在问题中列出足够的代码来明确显示您在哪里出错。

在您的代码中查找任何显示“insertObject:atIndex:”的行。您插入的对象显然为零。

如果您找不到此行,请查看 add a symbolic breakpoint on the symbol " [NSArray insertObject:atIndex:] "(单击链接以查看与您的问题密切相关的答案中的具体说明)并查看您是否可以在崩溃发生前立即中断。

关于ios - NSArrayM insertObject :atIndex:]: object cannot be nil',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17031736/

10-09 17:53