static NSArray *strLabels = [NSArray arrayWithObjects:@"姓名", @"性别", nil];
编译器报错:initializer element is not constant
为什么会给这种报错?我并没有把strLabels声明成const类型的啊。

解决方案 »

  1.   

    去掉static
      

  2.   


    去掉后是能用,但如果要加上static呢? 我是想让这个NSArray变量只被初始化一次。
      

  3.   

    应该这么写就可以了
    static NSArray *strLabels = nil;
    strLabels =[NSArray arrayWithObjects:@"", @"性别", nil];
      

  4.   

    这个是static 指针的定义和赋值问题
    正如:
    int *a = NULL;
    static int *b=a;//alizer element is not constant 同样的语法错误
      

  5.   

    [NSArray arrayWithObjects:@"姓名", @"性别", nil];
    构造的不是static类型变量。