How can I easily connect 2 views?

Discussion in 'iOS Programming' started by JamesFoote, Sep 23, 2008.

  1. JamesFoote macrumors regular

    JamesFoote

    Joined:
    Aug 5, 2008
    #1
    My app currently has a menu (that is not the mainview so it can't even be seen yet) and another 2 files (rootviewcontroller and mainview) that make up an RSS reding view. I want to be able to do 2 things:

    1. Make the menu the mainview
    2. Link one of the buttons on the mainview to the RSS view

    anyone who can help me out with this rocks - a whole lot!!!
     
  2. usuf24 macrumors newbie

    Joined:
    Aug 21, 2008
    #2
    Hi can you be more clear!!

    Anyways from what I have understood from the above quest, u want to make some view as the mainview and u wanna traverse from the mainview to the RSS View, if am not wrong..

    for your first question : In order to make any view to be displayed first, it shld have a WINDOW in its class declaration and its NIB file shld be mentioned as the first NIB in the pInfo.list file if you are using the IB..

    for ur second quest: Just create an Instance of that view controller which you wanna goto and then add its view as a subview to the mainview's window....

    Regards,
    Usuf
     
  3. iphonejudy macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #3
    Hi ,

    I use the below code ,But its not working.
    Can you please tell me what is the error in the code?

    #import "TestViewController.h"
    #import "Test2ViewController.h"


    @implementation TestViewController
    @synthesize view2Controller;

    -(IBAction)display:(id)sender
    {




    //Load the view controller from the HelloView nib file.
    Test2ViewController *vController = [[Test2ViewController alloc]
    initWithNibName:mad:"Test2View" bundle:[NSBundle mainBundle]];

    //set the view.
    self.view2Controller = vController;

    //release the view controller.
    [vController release];


    }


    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    // Initialization code
    }
    return self;
    }





    // If you need to do additional setup after loading the view, override viewDidLoad.
    - (void)viewDidLoad {



    Test2ViewController *view2 = [[Test2ViewController alloc] initWithNibName:mad:"Test2View" bundle:[NSBundle mainBundle]];
    self.view2Controller = view2;
    [view2 release];

    }



    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }


    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
    }


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


    @end
    Thanks
    judy
     
  4. usuf24 macrumors newbie

    Joined:
    Aug 21, 2008
    #4
    Traversing through views

    Hi,


    U are not adding ur newly created view controller's view to the window.

    so just use [window addSubView:viewController.view]; after u create the view controller's instance............in ur IBAction display......


    Regards,

    U'suf
     
  5. iphonejudy macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #5
    Hi

    When i run the application.The view2 is not displayed.I got the following warning message.

    warning: 'UIWindow maynot respond to -addSubView'

    Here my code is,

    Code:
    -(IBAction)display:(id)sender
    {
    	//Load the view controller from the HelloView nib file.
    	Test2ViewController *vController = [[Test2ViewController alloc] 
    										initWithNibName:@"Test2View" bundle:[NSBundle mainBundle]];
    		//set the view.
    	self.view2Controller = vController;
    	
    	//release the view controller.
    	[vController release];
    	
    	
    
    	[window addSubView:view2Controller.view];
    
        [window makeKeyAndVisible];
    }
    
    Can anybody please tell me the solution?

    Thanks
    judy
     
  6. usuf24 macrumors newbie

    Joined:
    Aug 21, 2008
    #6
    Hi,

    use [self.view.window addSubView:viewController.view];

    Regards,

    usuf
     

Share This Page