初始化元素不是编译时常量错误 [英] Initializer element is not a compile-time constant error

查看:280
本文介绍了初始化元素不是编译时常量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程式中执行 IIViewDeckController

I am implementing IIViewDeckController into my app.

当我试图替换IBAccount去到那个屏幕时,我得到一个错误:

When I am trying to replace the IBAccount to go to that screen I get an error:


初始化程序元素不是编译时常数

Initializer element is not a compile time constant

代码的第一部分是我现在的代码, UIViewController 来自 IIViewDeckController ,我想用来加载 FirstAccountViewController over。

The first section of the code is what I have now, and the UIViewController is from the IIViewDeckController that I want to use to load the FirstAccountViewController over.

-(IBAction)account{
    FirstAccountViewController* ab=[[FirstAccountViewController alloc] init];
    [self.navigationController pushViewController:ab animated:YES];
    UIViewController* leftController = [[UIViewController alloc] init]; 
}

UIViewController* leftController = [[FirstAccountViewController alloc] init]; 
IIViewDeckController* deckController =  [[IIViewDeckController alloc] initWithCenterViewController:self.centerController leftViewController:leftController
                                                                           rightViewController:rightController];


推荐答案

>

You've declared global variables here:

UIViewController* leftController =
    [[FirstAccountViewController alloc] init]; 
IIViewDeckController* deckController =
    [[IIViewDeckController alloc] initWithCenterViewController:self.centerController leftViewController:leftController rightViewController:rightController];

您尝试在没有上下文的情况下初始化它们(例如您传递的参数 - 没有全局 self )。

and you're trying to initialize them without context (e.g. the parameters you pass -- there should be no global self).

这里不需要一个全局变量,因为它不能在这个上下文中正确初始化,并且因为它在C和ObjC中形成。

You don't want a global variable here, and you cannot declare it as such because it cannot be initialized properly in this context, and because it's ill formed in C and ObjC.

我建议在这种情况下使用ivar。

I recommend using an ivar in this case.

这篇关于初始化元素不是编译时常量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆