Reputation: 1171
This question might have been answered, if yes, please share the link.
I have created a Single View Application, It works fine, but now I have added a new view and on a button click, wants the new view to appear.
This is the code for click action,
SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:settingsViewController animated:YES];
The Default ViewController now looks like this in .h file
@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
The SettingsViewController.m has a default
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{}
Can I add another view to "Single View Application" like this or should I chose another template for my project ?
Thanks.
Upvotes: 1
Views: 1725
Reputation: 1171
In iOS 5, switching between views works a bit different i think,
I have created a few apps with the above mentioned code for switching views.
But now, I have to write it like this to work:
SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:settingsViewController animated:YES];
Upvotes: 0
Reputation: 4388
You need to create a UINavigationController
in your AppDelegate
. Then make your ViewController
the rootViewController
of the UINavigationController
. Then you will be able to push and pop views.
Here is the code to create the rootViewController
where mainNavigationController
is the UINavigationController
in your AppDelegate
:
ViewController *vc = [[ViewController alloc] init];
mainNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
Once you have the ViewController
set up as the rootViewController
it will conform to the UINavigationController
push and pop methods to create a stack of UIViewController
s.
Upvotes: 1
Reputation: 879
That is fine. The single view application template is just a barebones template. You can add any type of navigation you like to it.
Upvotes: 1