NavigationBar and ToolBar are not showing in the simulator. I went through similar questions posted in this forum and included what I learnt from the answers. Still I'm unable to figure out why the bars are not shown.
I also included the following lines to the viewWillAppear()
//Show toolbar and navbar
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController?.setToolbarHidden(false, animated: true)
Below is the screenshot of my storyboard.
The simulator screenshot appears like
I reach this view controller from a TableViewController (which is embedded in TabBarController) programmatically, with the following code
var nextController = ImagePickViewController()
nextController = self.storyboard?.instantiateViewControllerWithIdentifier("ImagePicker") as! ImagePickViewController
self.presentViewController(nextController, animated: true, completion: nil)
Any help is much appreciated. Please let me know if additional information is required.
Thanks in advance
Hari
Thank you James from Udacity. Posting his diagnosis.
The toolbars didn't show up because I used presentViewController. So the embedded navigation controller was bypassed and the ImagePickViewController was presented directly.
Solution is to start the navigation controller using the segueIdentifier.
I added a segue from my TableViewController to the Navigation Controller (of the ImagePickViewController). In the attribute inspector for this segue, I set the Identifier as "startImagePicker". In the TableViewController code, I start the ImagePickViewController by calling performSegueWithIdentifier -
self.performSegueWithIdentifier("startImagePicker", sender: self)
Thanks
Hari
Related
i am currently working on a menu bar application for OS X. I want do display some data in a NSTableView within the menu. I already managed to set the view of the first NSMenuItem to my NSScrollView.
The problem is that i don't know how to set the maximum height for the NSScrollView. I want something similar to the Shazam or Adobe Creative Cloud app: A small menu with a TableView inside it that scrolls but doesn't fill the entire height of the screen.
Here is what i currently have:
The way it works now is that the menu automatically fills the entire screen depending on how much data i put into the TableView.
Here is a screenshot of the way the Shazam app does it:
They display lots of information inside the table but restricted the NScrollView to have a fixed height.
I don't think this is hard to do but i don't know where to look for the option.
Any help would be really appreciated :)
Regards,
Timo
I finally figured it out! I assigned the wrong view to the NSMenuItem.
Now i have two outlets inside my AppDelegate:
#IBOutlet weak var myMenuItem: NSMenuItem!
#IBOutlet weak var myScrollView: NSScrollView!
Inside applicationDidFinishLaunching() i assign the NSScrollView to the view property of the NSMenuItem:
func applicationDidFinishLaunching(aNotification: NSNotification) {
...
self.myMenuItem.view = myScrollView
...
}
The problem i used to have that i set the menu items view to the NSTableView directly, not to the NSScrollView. Everything works fine now.
Thats what the result is looking now:
Exactly what i wanted :)
Regards,
Timo
Design mode everything is fine but in live Navigation Bar goes under the ScrollView How am I gonna solve this problem ? Please help
Again, without seeing any code at all it is hard to say, but I believe that the navigationBar isn't displaying at all. If you're presenting the UIViewController directly from another view, you're not instantiating the UINavigationController it is embedded in.
A solution would be to either create a segue in your storyboard from your presenting view to the UINavigationController, or add a storyboardId to the UINavigationController and instantiating as:
let nav = storyboard.instantiateViewControllerWithIdentifier("STORYBOARD_ID_HERE") as! UINavigationController
presentViewController(nav, animated: true, completion: nil)
If you can show some code on how the view is presented you'll receive better help, since it's impossible to know exactly what is wrong based on just one image.
I have created a CustomViewController and layed it out in interface builder. Then I am all set to use the CustomViewController's view as a subview in another viewcontroller but when I add it to the other viewcontroller the layout of the custom uivewcontroller becomes wrong.
What can cause this? What is the propper way to do this?
The whole project can be found here https://github.com/agustr/STHLMPubCrawl just download and run (in an iphone 5 simulator). If there is any question about how it should look you can just move the initial view pointer to the 'place view controller cene'
this is the code:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("GPPlaceViewController") as? GPPlaceViewController
if vc != nil{
vc?.view.layer.borderWidth = 4
vc?.view.layer.borderColor = UIColor.redColor().CGColor
self.GPPlaceView.layer.borderColor = UIColor.yellowColor().CGColor
self.GPPlaceView.layer.borderWidth = 2
vc?.view.frame.size = self.GPPlaceView.frame.size
self.GPPlaceView.addSubview(vc!.view)
}
else {
print("could not load GPPlacePageViewController from storyboard")
}
Any help is welcome.
I am unsure if this method of adding a VC's view to another view is wrong or outdated but I seem to remember it working at some point. I contacted apple and they told me to use a ContainerView. It is supposedly explained in detail in this talk 'Implementing UIViewController Containment' https://developer.apple.com/videos/wwdc/2011/.
The biggest problem I had when using the containment View was that you can not drag the segue in interface builder but you have to right click or controll click to point the segue to the appropriate place. Then you can treat that segue as any other in your parent viewcontroller that is to say the viewcontroller that contains the container view.
I am working on a Yosemite app in swift and have hit a road block.
I have multiple views working properly, and now I want to implement custom menu actions. To keep the answer simple, how would I achieve this example. I want to click a menu button and have it change text on the viewcontroller. I have tried setting up IBActions, but I'm not sure how to make the link to the viewcontroller from the AppDelegate. How do you connect the two?
I'm still figuring this stuff out, so any insight would be awesome. Thanks in advance.
*UPDATE. I tried making a object and linking it that way. No luck.
When you press "Test" it prints test, however it's in it's own class. I need to do something in my main ViewController class. How to I make that reference?
Getting NSViewController from NSWindow is an easy solution.
If your app has multiple windows, select appropriate one through keyWindow or windows of NSApplication.
#IBAction func pressed(sender: AnyObject) {
if let window = NSApplication.sharedApplication().mainWindow {
if let viewController = window.contentViewController as? YourViewController {
// do stuff
...
}
}
}
I have been scouring the web for the best and most proper way to dismiss/unwind a view using Swift and cannot find a definitive answer. For ease of concept, I have two views and have linked one to the other with a button and a segue using "show." How do I return to the original view (no data needs to be passed)?
you can try adding a button action to your ViewController2 and add in the code below. Your ViewController2 will dismiss when the button is being pressed.
dismissViewControllerAnimated(true, completion: nil)