Junior Bill gates
Junior Bill gates

Reputation: 1866

switching views in iphone

i m making a client server program in which i want to switch from one view to another but i am getting an error in "clientserverprogram view.m" plz help

"clientserverprogram view.h" 

#import <UIKit/UIKit.h>

@class secondview;

@interface clientserverprogramViewController : UIViewController {

    IBOutlet UITextField *name;
    IBOutlet UITextView *filepath;
    IBOutlet UIButton *print;
    IBOutlet UIButton *settings;
    IBOutlet UIButton *cancel;
    IBOutlet UILabel *display;
    IBOutlet secondview *secondview;
}

-(IBAction) print;
-(IBAction) settings;
-(IBAction) cancel;

@property (nonatomic , retain) IBOutlet UITextField *name;
@property (nonatomic , retain) IBOutlet UITextView *filepath;

@property (nonatomic , retain) IBOutlet UILabel *display;
@end




"clientserverprogram view.m"


#import "clientserverprogramViewController.h"
#import "secondview.h"


@implementation clientserverprogramViewController

@synthesize  name ,filepath,display ;

-(IBAction) print {

    NSString *str = name.text;


    [display setText : str];

}

-(IBAction) settings {


    [self presentModalViewController: secondview animated: YES ];

"" error: expected expression before 'secondview'"" 


}


-(IBAction) cancel {


    exit(0);

}


- (void)dealloc {
    [super dealloc];
}

@end


"secondview.h"


#import <UIKit/UIKit.h>


@interface secondview : UIViewController {

    IBOutlet UIView *view;

    IBOutlet UIButton *back;

}

-(IBAction) back;



@end



""secondview.m""


#import "secondview.h"


@implementation secondview




-(IBAction) back {

    [self.parentViewController dismissModalViewControllerAnimated: YES];
}


- (void)dealloc {
    [super dealloc];
}


@end

Upvotes: 0

Views: 319

Answers (3)

Anshuman
Anshuman

Reputation: 25

if you are not using the NIB file then just create the object of second page with init mathod and use this

[self.view addsudView:secondView.view];

Upvotes: 1

user745098
user745098

Reputation:

I used your code and the problem here is your class name "secondview" and the instance you are making from it IBOutlet secondview *secondview are same. Please use different name for class names and the instances you create.

Always start with uppercase for class names and start with lowercase for class instances you create. Hence, your class name should be SecondView and you should write IBOutlet SecondView *secondView.

Or you should just use different names. Its very confusing.

Upvotes: 0

Sarah
Sarah

Reputation: 1595

[self presentModalViewController: secondview animated: YES ];

"" error: expected expression before 'secondview'""

This line of code is responsible to present modal ViewController. In your case you only had a view. So either you create a controller for the second view like that:

SecondViewController *secondController=[[SecondViewController  alloc] initWithNibName:@"secondView" bundle:[NSBundle mainBundle]];
 [self presentModalViewController:secondController animated: YES ];

or you can load you second view from nib file using outlet and you can add it as subview to your current view controller view:

[self.view addSubView:secondview]; 

Update

As I can see on your code SecondView is your controller not the view, but you are try to present a controller that is not initialized. I also noticed that you have an outlet for your view on SecondView, when you create a new sub class of UIViewController you can check the option that creates a .xib file as well.

Hope that helps,

Upvotes: 2

Related Questions