I am trying to load a new view when I click a button in the app.
The error I am getting is –
View Switcher[6867:207] -[UIView pushViewController:animated:]: unrecognized selector sent to instance 0x6010660
and the source code snippet is –
-(IBAction) blueButtonPressed:(id)sender{
if(self.yellowViewController == nil){
YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
self.yellowViewController = yellowController;
//[yellowController release];
//[self.view addSubview:yellowController.view];
//[self.view pushViewController:self.yellowViewController];
[self.navigationController pushViewController:self.yellowViewController];
[yellowController release];
}
//[self.navigationController pushViewController:self.yellowViewController animated:YES];
}
Here is the header file I am using –
#import <UIKit/UIKit.h>
@class BlueViewController;
@class YellowViewController;
@interface BlueViewController : UIViewController {
YellowViewController *yellowViewController;
BlueViewController *blueViewController;
}
-(IBAction)blueButtonPressed:(id)sender;
@property(retain) YellowViewController *yellowViewController;
@property(retain, nonatomic) BlueViewController *blueViewController;
@end
The link to the xcode project is – https://rapidshare.com/files/2403429896/View_Switcher.zip
pushViewController is a UINavigationController method.
I’m assuming you are in a UIViewController subclass
Could you post an Xcode project I need to see this.
Ok, I’ve look into your code, the problem is that you don’t have any navigationController. Your app is structured like a view base application not like a navigation base application.
The result is that your self.navigationController == nil, that is why that call is ignored.
In your application delegate you need some code looking like this
In the applicationFinised…
In your code, when you click on your switch in the toolbar, it’s “working” because your using this code :
And there is no navigationController in that process.