Reputation: 347
In Xcode there is a template with two controllers and navigation bar. One of them is a table view.
But I need navigation bar with simple view. So, I create new view controller and delegate a root from navigation bar to this view controller.
But instead of my view controller I see just white screen. I suppose it is navigation bar screen. How can I automatically get into my root view controller?
// MainViewController.h
#import <UIKit/UIKit.h>
@class ViewController;
@interface MainViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *editButton;
@property (strong, nonatomic) ViewController *detailViewController;
@end
/
/
// MainViewController.m
#import "MainViewController.h"
#import "ViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
Upvotes: 0
Views: 182
Reputation: 852
Here is another way.
Open the storyboard, delete the table view controller (the item connected to the navigation controller. Drag a new View Controller on the screen. Control drag from the navigation controller to your view controller and select root view from the pop up. You now have a basic view controller with a navigation controller.
Upvotes: 0
Reputation: 346
To achieve your requirement, please open your story board and follow these steps: 1. From the inspector drag the navigation Controller into the story board pane. 2. It will automatically create a Root view controller which you don't want, delete that. 3. Check the "Is Initial View Controller" from the attribute inspector (4th tab in the inspector). 4. Select your view controller, go to inspector connection the link the "relationship" to the navigation controller (last tab in the inspector) and make is as root view controller.
Now your done. Hope this will help you.
Upvotes: 0
Reputation: 1075
It seems like you actually are seeing what you want to see. It's just hidden behind the navigation bar. Try re-positioning your label and button so that their y is below that of the navigation bar.
You should be able to see a navigation bar in the view controller through the storyboard, though. Try dragging a new view controller into the storyboard, select it and go to Editor -> Embed in -> Navigation Controller. Then just recreate it.
Also, on a side note, your Details view probably doesn't need a segue back to your Bar Code view. When you have a navigation controller and set the segue from Bar Code to Details as "push", there will be a Back button for you to go back.
Upvotes: 1