0

I am implementing IIViewDeckController into my app.

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

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];
5
  • What are those variables doing outside of a method body? What are they for, and where are you trying to use them? Commented Apr 28, 2012 at 20:33
  • @JacquesCousteau they're the not-a-compile-time-constants (end sarcasm) Commented Apr 28, 2012 at 20:36
  • @H2CO3: I'm not sure if your sarcasm is directed at me; I know what the error means, but I'm trying to figure out what Max wants to do with the variables so that I can answer the question in a productive way. Commented Apr 28, 2012 at 20:38
  • @JacquesCousteau of course no. It's directed towards OP who should have rtfm. Commented Apr 28, 2012 at 20:39
  • @JacquesCousteau I am I just trying to have that effect applied to that IBAction and have it load the FirstAccountViewController for that effect. I know that those lines don't work, I was just putting them both there to see what to do with it...Sorry still learning here :) Commented Apr 29, 2012 at 0:40

2 Answers 2

1

You've declared global variables here:

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

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

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.

I recommend using an ivar in this case.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so much. Still just getting use to objc so forgive me for not knowing.. Do I need to put the UIViewController in the IBAction class to be able to have that run when the button is pushed?
@MaxRoper there is no right answer -- it depends on your app's logic.
0
UIViewController* leftController = [[FirstAccountViewController alloc] init]; 
IIViewDeckController* deckController =  [[IIViewDeckController alloc] initWithCenterViewController:self.centerController leftViewController:leftController rightViewController:rightController];

Yeah, that's wrong -- if you want to initialize global variables on startup (although you're not at all advised to use global variables), you'll need to use an initalizer function:

UIViewController *leftController;
IIViewDeckController *deckController;

__attribute__((constructor))
void __init()
{
    leftController = [[FirstAccountViewController alloc] init]; 
    deckController =  [[IIViewDeckController alloc] initWithCenterViewController:self.centerController leftViewController:leftController rightViewController:rightController];

}

2 Comments

Does that need to be applied as a global variable if I just want to have it work for that one page?
No, but since your original question contained global variables, I used them as well. Nevertheless, they're discouraged to use unless you have a very good reason to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.