Here are two screenshots, my Storyboard:
And my emulator:
I have localized the problem further. I have a login screen which I show if the user is not logged in. the navigation bar is not visible only after login: I suppose it has to do with the way I switch from login screen to the root view controller. Here is the way I do it:
func switchToMainScreen() {
let rootController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("homeView");
self.presentViewController(rootController, animated: true, completion: nil)
}
Can anyone help me as to why there is no Navbar + Navbar item in my emulator?
I can't post comment on your question for my reputation, check "bar visibility" at attributes from your storyBoard.make sure it's checked, maybe it's unchecked.
i can't post image in my answer, see following link for more info:
http://i.stack.imgur.com/1k4WU.png
tell me the result to check another odds.
//UPDATE
I think you need to embed your viewController in NavigationController . I mean:
delete your NavigationController from storyBoard,
second select your viewController
then from top menu bar select "Editor" -> "Embed in" -> "navigationController"
it automatically create an navigation Item which can contain navigation items.
From screenshot it looks ok. The only thing that I worry about is the navigation bar in your view controller with title as "Title".
Could you please try this:
Delete the Navigation Controller from your storyboard.
Delete the custom navigation bar in your view controller.
Select your View Controller in your story board, then choose
"Editor" in your menu, then "Embed in" => "Navigation Controller".
Finally, in your view controller' viewDidLoad:, try the following:
->
self.navigationItem.title = #"My Title";
self.navigationItem.rightBarButtonItem = // Set your right bar button item here
EDIT: Post OP question update:
Since your entry point is not the story board driven and you have an initial login screen, I would advise you to create your own UINavigationController and embedded your storyboard view controller into it and then present it. It must work!!!
func switchToMainScreen() {
let rootController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("homeView")
let navigationController = UINavigationController(rootViewController: rootController)
self.presentViewController(navigationController, animated: true, completion: nil)
}
PS: Remove the embedded Navigation Controller from storyboard then.
Related
Well, I'm faced with misunderstanding.
I want my UITabBar to stay displayed when I make a segue from my History button (see picture).
My segue is on Show.
My view is embed in a UINavigationController that is root controller at my UITabBarController.
"Show navigation bar" is turned off on my UINavigationController.
And with all that, I have a grey screen on my segue and no UITabBar...
Thank you in advance!
Try creating a popup view.
In the storyboard remember to set the identifier for the view controller that you are going to. Then delete the segue.
let customAlert = self.storyboard?.instantiateViewController(withIdentifier: "view") as! yourViewController
self.addChild(customAlert)
self.view.addSubview(customAlert.view)
customAlert.view.backgroundColor = UIColor.white
Please make Segue kind as "Show". When select as "Show Detail", the ViewController is present over the Tabbar and hides it.
I have implemented SWRevealViewController into my project successfully. The side menu is a UITableView with different cells which navigate to differing view controllers. When I tap on the 'profile' cell it defaults to the LoginViewController, there the user will login in and, once verified, will go to the ProfileViewController. This leads to my problem, when I navigate to the ProfileViewController the Navigation bar button (on the left) does not work properly. Likewise, when I press the logout button (the right navigation bar button) it does navigate back to the LoginViewController, however, the menu button does not work.
My navigation functions are as follows:
func switchVC() { //Navigates to the profileViewController
let storyboard = UIStoryboard.init(name: "Login", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("Profile")
UIApplication.sharedApplication().keyWindow?.rootViewController = nav
}
func switchBack() { //Navigates back to the LoginViewController
let storyboard = UIStoryboard.init(name: "Login", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("Login")
UIApplication.sharedApplication().keyWindow?.rootViewController = nav
}
My storyboard is as follows:
Any help that you may be able to provide would be greatly appreciated. Thank you everyone!
Cheers
Your question is somewhat difficult to answer, but maybe this will help. In order for SWReveal View Controller to work, you always have to route to the main SWReveal Controller Scene for the menu button to work. For example, if my storyboard looked like
SWRevealViewController Scene --> Navigation Controller Scene --> Main View
and I routed back to the Navigation Controller Scene, the button would not work. You have to route back to the first Instance of the SWRevealController Scene that comes before the navigation / any other scenes you are trying to reach.
If you need to add another instance of SWRevealViewController Scene to make that work, just segue through the sw_front identifier to the navigation controller/ view controller you need the button to work in, and then segue it through the sw_rear identifier back to the same one instance of the menu.
Sorry if this answer is confusing, please let me know if I can clarify anything.
First of all, I don't want to use storyboards at all. I am able to "present" the targeted view controller, but I can't get it to show with the standard iOS back button at the top. My understanding is I can get this to work by pushing the controller instead of presenting it. I don't get any errors, but nothing happens.
On a button click this code is run. The commented code is what successfully presented the ForgotPasswordPage :
// Changes to Forgot Password Page
func forgotPasswordSwitch(sender: UIButton!) {
//let ForgotPassword:ForgotPasswordPage = ForgotPasswordPage()
//self.presentViewController(ForgotPassword, animated: true, completion: nil)
let ForgotPassword = ForgotPasswordPage()
self.navigationController?.pushViewController(ForgotPassword, animated: true)
}
You have to manually create a UINavigationcontrollerto get the back bar. To do this you can use the code from this answer, which achieves this by using this code:
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var nav1 = UINavigationController()
var mainView = ViewController() //ViewController = Name of your controller
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window?.makeKeyAndVisible()
Here just add all the ViewControllers you want to be under the Navigation controller into the array and then push between them.
Hope that helps, Julian
I know that sometimes it's much better develop apps programmatically, but there are many time that Storyboard can save you a lot of time. You just simply use it for this situations...
1) In you Storyboard, localize the view controller you want to enable for pushing
2) Select it and find the "Editor" in your top bar
3) Select Editor->Embed In->Navigation Controller
And now your view controller it's ready for pushing
I am new to Swift and have been struggling with this for a while.
I am trying to redirect users based on login status to either "Login" viewcontroller or "Home" viewcontroller.
"Home" viewcontroller has NavigationBar and TabBar and it shows a table. But, when i use the following code, i see only the table. NavigationBar and TabBar are not shown at all.
var view = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as UIViewController
self.presentViewController(view, animated: true, completion: nil)
Here is my storyboard : https://www.dropbox.com/s/dkcz45n8000gua6/storyboard.png?dl=0
Any help would be appreciated!
Edit (used TabBarController):
var view = self.storyboard?.instantiateViewControllerWithIdentifier("MainTabController") as UITabBarController
self.presentViewController(view, animated: true, completion: nil)
Your problem has nothing to do with being new to swift; it has to do with not understanding storyboards. If you instantiate HomeViewController, and present it, then that's all you will get. The fact that it's embedded in a tab bar controller and navigation controller in the storyboard is not "known" to this bare controller you just instantiated. You should instantiate the tab bar controller instead, and present it. It will take care of instantiating any of its children, and the navigation controller will take care of instantiating its root view controller.
I have a Storyboard and I have added the default UITabViewController, which has two UIViewControllers.
-FirstViewController
-SecondViewController
So the root arrow point to the tab bar controller in the Storyboard.
Now I have added a LoginViewController (that isn't a tab of the Tab Bar).
In the AppDelegate file, in the didFinishLaunchingWithOptions method if the user is yet authenticated, the application is going to show the first tab. Did I code it right?
Please look at the code below:
//inside didFinishLaunchingWithOptions
...
var storyboard = UIStoryboard(name: "Main", bundle: nil);
var tabController = storyboard.instantiateViewControllerWithIdentifier("TabBar") as UITabBarController;
if(self.window != nil){
self.window!.rootViewController = tabController;
}
The Tab Bar Controller doesn't have a custom class associated but the generic one. Did I take the right approach?
This is correct for manually instantiating a storyboard as a root view controller. However, manually setting the rootViewController in didFinishLaunchingWithOptions isn't a great strategy. For one, you have to manually load the storyboard and then instantiateViewControllerWithIdentifier, which is inflexible and can break.
If you want to show a login screen first if the user is not logged in, try:
if (checkUserNotLogedIn()) {
//user not logged in
var loginViewController = CustomLoginViewController()
self.window?.rootViewController?.presentViewController(loginViewController, animated: false, completion: nil)
}
Now your custom login controller is sitting on top of the tabBar.