0

ok, this may be a very basic question and I apologise if it is, but its driving me mad and I really need to get a better understanding.

I have an app that I am developing and using a new view controller and xib file for each page.

I call each page by using this code:-

HelpVC = [[[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle: [NSBundle mainBundle]]autorelease]; [self presentModalViewController:HelpVC animated:YES]; 

Which works great.

However if I have this declared in a file and I then want to call it somewhere else I am getting errors all over the place.

is there any way to initialise all the xib files first in a class file and then call them from that file when needed??

Thanks

This is the error I get back

error: expected specifier-qualifier-list before 'UserInputViewController'

It seems to cause all of my declarations in the .h file to error with the message above.

Some sample code is:-

.h file

#import <UIKit/UIKit.h> #import "CgePWViewController.h" #import "LogBackInViewController.h" #import "LoginViewController.h" @interface SettingsViewController : UIViewController { CgePWViewController *cPWVC; LogBackInViewController *LBIVC; LoginViewController *login; } @property(nonatomic, retain) CgePWViewController *cPWVC; @property(nonatomic, retain) LogBackInViewController *LBIVC; @property(nonatomic, retain) LoginViewController *login; 

so basically as soon as I have added in LoginViewController it causes everything else to error, if I take this out then the app runs perfectly.

1
  • 1
    Please add the code the exact code that gives the error, and also the exact error message, so that we can try and help you. Commented Aug 6, 2012 at 18:31

2 Answers 2

1

Does your LoginViewController.h imports the SettingsViewController as well? It seems to be a "cross reference" (I don't know if this term makes sense in English as it does in Portuguese).

Before your

@interface SettingsViewController : UIViewController 

put a

@class LoginViewController; 

and check if it helps.

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

4 Comments

Hi, yes there is cross referencing hence why I wanted to maybe load the view controllers at the start of the app and reference them throughout the app. I will try what you suggest.
That worked, so should I use @class instead of #import for all the view controllers?
Here, this will help you clarify your doubt.
funny enough I was just reading that post. Thanks for all your help.
0

Don't initialise your view controllers to put them in properties. Instead, create them as soon as you need them.

Let's assume you want to show a view controller when somebody pushes a button. Add this method to your view controller (let's assume it's named MyFirstViewController):

- (IBAction)someButtonDidPush: (UIButton *)sender { MySecondViewController *vc = [[MySecondViewController alloc] init]; // Do stuff and then show it. One way may be like this: [self presentViewController: vc animated: YES completion: nil]; } 

Just hook up the button with the method above. No properties needed! You're (probably) done.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.