View Full Version : How can I easily connect 2 views?
JamesFoote
Sep 24, 2008, 12:35 AM
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!!!
usuf24
Sep 24, 2008, 02:23 AM
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!!!
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
iphonejudy
Sep 24, 2008, 06:54 AM
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:@"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:@"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
usuf24
Sep 25, 2008, 01:18 AM
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
iphonejudy
Sep 26, 2008, 01:41 AM
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,
-(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
usuf24
Oct 8, 2008, 05:28 AM
Hi,
use [self.view.window addSubView:viewController.view];
Regards,
usuf
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.