Here i m sending my code for presentmodelViewController

Posted by aman-gupta on Stack Overflow See other posts from Stack Overflow or by aman-gupta
Published on 2010-04-19T15:46:05Z Indexed on 2010/04/19 15:53 UTC
Read the original article Hit count: 713

Filed under:

Hi Please help me out i want to switch to first view from third view directly here is my code:-where i m using presentModelViewcontroller

//
//  ExperimentAppDelegate.h
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

@class ExperimentViewController;
@class SecondView;
@class ThirdView;

BOOL parentScreenNo;
@interface ExperimentAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    ExperimentViewController *viewController;
    SecondView *ptrSecond;
    ThirdView *ptrThird;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ExperimentViewController *viewController;
@property (nonatomic, retain) IBOutlet SecondView *ptrSecond;
@property (nonatomic, retain) IBOutlet ThirdView *ptrThird;

@end

/////////////////////////////////////
//
//  ExperimentAppDelegate.m
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "ExperimentAppDelegate.h"
#import "ExperimentViewController.h"

@implementation ExperimentAppDelegate

@synthesize window;
@synthesize viewController,ptrThird,ptrSecond;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    parentScreenNo = NO;
    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end
/////////////////////////////////////////

//
//  ExperimentViewController.h
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ExperimentViewController : UIViewController {

}
-(IBAction)second:(id)sender;

@end

///////////////////////////////
//
//  ExperimentViewController.m
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "ExperimentViewController.h"
#import "ExperimentAppDelegate.h"

@implementation ExperimentViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/
-(IBAction)second:(id)sender
{
    ExperimentAppDelegate *app = (ExperimentAppDelegate *)[[UIApplication sharedApplication]delegate];
    [self presentModalViewController:app.ptrSecond animated:YES];

}

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


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

@end
/////////////////////////////////
//
//  SecondView.h
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface SecondView : UIViewController {

}
-(IBAction)third:(id)sender;
-(void)down;
@end

////////////////////////////////////////////
//
//  SecondView.m
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SecondView.h"
#import "ExperimentAppDelegate.h"


@implementation SecondView

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

}
-(void)viewWillAppear:(BOOL)animated
{
    if(parentScreenNo == YES)
    {
        [self performSelector:@selector(down) withObject:nil];

    }


    [super viewWillAppear:YES];
}

-(IBAction)third:(id)sender
{
    ExperimentAppDelegate *app = (ExperimentAppDelegate *)[[UIApplication sharedApplication]delegate];
    [self presentModalViewController:app.ptrThird animated:YES];

}
-(void)down
{
    [self dismissModalViewControllerAnimated:YES];  
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

}


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


@end

//////////////////////////////////
//
//  ThirdView.h
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface ThirdView : UIViewController {

}

-(IBAction)back:(id)sender;

@end

//////////////////////////////////
//
//  ThirdView.m
//  Experiment
//
//  Created by Aman on 4/20/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ThirdView.h"
#import "ExperimentAppDelegate.h"


@implementation ThirdView

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/
-(IBAction)back:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
    parentScreenNo = YES;
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


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


@end

Above is my code for calling other view please tell how i can call my first view by using dismismodelViewController from third screen Please help me out

© Stack Overflow or respective owner

Related posts about iphone