I would like to make an "inspector sidebar" in a macOS window. You know the inspector in Xcode:
The sidebar's content should be context sensitive. Depending on the user's selection in the main window there should be different dialogs.
Which technologies do I have to use to get this behavior?
My attempts were (in Storyboard):
Insert a Split View into the window.
Insert a Tab View Controller into the right Custom View of the Split View
But this didn't worked: I could easily insert the Split View into the window. And I could easily insert a Tab View Controller to the Storyboard. But I was not able to insert the Tab View Controller into the right view of the Split View.
So how do I achieve the desired behavior?
Finally I solved the issue. I had to add a CustomView to each of the tab's CustomViews. This way, Xcode added ViewControllers automatically. Here are the individual steps:
First, I had to insert a SplitView into the storyboard. Nothing problematic here yet.
Second, I've added a TabView (Style: tabless) into one of the CustomViews:
And third, I needed to add ContainerViews to each of the tabs:
This way Xcode added ViewControllers for each of the tab's ContainerViews:
No I can chose the different Tabs programmatically:
#IBAction func showInspector1(_ sender: NSButton) {
self.tabView.selectTabViewItem(at: 0)
}
#IBAction func showInspector2(_ sender: NSButton) {
self.tabView.selectTabViewItem(at: 1)
}
I would like to thank for the comments, that helped me making progress and solving this issue.
Related
Im developing an osx application in Swift 4 to be displayed in the menu bar and call a popover when clicked to display a number of different views.
My structure in Storyboard is:
NSView > Container View > Tab View
This lets me maintain a top menu bar while being able to change between tabs.
I have hidden the buttons in the NSTabView and have managed to change between views on load using the following code:
import Cocoa
class TabViewController: NSTabViewController {
#IBOutlet weak var theFirstTab: NSTabViewItem!
override func viewDidLoad() {
super.viewDidLoad()
changeTab()
}
func changeTab() {
let theTabView = theFirstTab.tabView
theTabView?.selectTabViewItem(at: 3)
}
}
When I start my application this loads the 3rd tab programatically which is great!
What I want to do however is create my own menu in the parent ViewController to call this function so that the tabs change within the container.
Is it possible to call this function from the parent somehow?
Ive searched all over for a solution to this problem and am so close but hopefully someone here can help me. I can add pictures of my storyboard if this is not clear enough?
Thanks in advance.
I want to create an app in Xcode 8.0 that lets the user press a bar button item in the navigation bar. Once this button has been clicked an unwind segue will take place whilst also printing, "helloWorld" to the output section at the bottom of Xcode. I have successfully created an unwind segue using:
#IBAction func unwindToViewController (sender: UIStoryboardSegue){
}
I then linked this to the bar button item on the navigation bar so that when I tap the bar button item on the navigation bar the view disappears downwards.
I am trying to simply print("helloWorld") onto the output section at the bottom of Xcode when I press the done button but nothing appears on the output section. So far I have:
#IBAction func add(_ sender: AnyObject) {
print("helloWorld")
}
in the View Controller Swift File for that View Controller.
For unwind We need to remember only two points
1) We need to put below method into Destination ViewController.It is a place where we want to navigate to. Here method name can be different but arguments matter a lot.
#IBAction func unwindToDestinationViewController (sender: UIStoryboardSegue){
}
2) Go to the Source viewController from where you want to go back. Now click on unWind button on top right and Control-Click and set outlet to the Back button(Example)
Kindly check this post on stack overflow. This is a duplicate of below post.
You can find the answer in the given below link.
https://stackoverflow.com/a/39916477/2894335
This Blog gives a very nice introduction to unwind segues. article link here.
Try the following tutorial will fix your problem and help you to understand more about how to perform unwind segue...
https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/#identifier
http://ashishkakkad.com/tag/uistoryboardsegue/
Hope this helps...
I need several view controllers to segue back to a main menu. After adding the terminal segues, by adding a button and creating a show segue, my storyboard looks like a rats nest of confusion. Is there a better way to link the terminal view controller back to a main menu, or is this how it's done?
After reading up, it looks like this is the best solution for my needs, since there is no data to push from the terminal view controller.
#IBAction func backToMain(sender: AnyObject) {
self.navigationController?.popToRootViewControllerAnimated(true)
}
I am trying to implement a split view controller using storyboards & swift on MacOS:
For some reason only the right side shows up. Any ideas ?
It's actually a window size issue. As it is undefined it push the left side out of view. Just place the cursor on the left side and drag to show the left view.
Hope it helps.
UPDATE:
It's actually NOT a window size issue. It looks like that the split view controller push one side out of view by default. Conversely, I was able to view the two panes correctly using the split view component inserted into a view controller.
I'll be checking for information about this issue in the latest WWDC:
https://developer.apple.com/videos/wwdc/2014/?id=212
https://developer.apple.com/videos/wwdc/2014/?id=214
UPDATE 03/11/14:
After minute 07:00 of the first screencast I got what was going on. Take a look at the screenshot below:
Make the Split View Controller as wide as the main window.
Resize the Split View Items.
Click on the items with the right most Split View Item, add Missing Constraints from the Pin pop up menu.
It may take few tries before you get it right. I tested it three times and it did work.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/index.html#//apple_ref/doc/uid/20001093
NSSplitViewDelegate
class SplitViewController: NSSplitViewController{//,NSSplitViewDelegate
Swift storyboards: split view controller not showing properly
It was really problem for me as well. Now I got solved this problem in my code.
1.Create a class extended NSSplitViewController.
2.Set a class created in phase1 as Custom class on your SplitView which you created on StoryBord.
3.call MySplitView.adjustSubviews() inside viewDidLoad().
import Cocoa
class SplitViewController: NSSplitViewController{//,NSSplitViewDelegate
#IBOutlet weak var MySplitView: NSSplitView!
override func viewDidLoad() {
super.viewDidLoad()
MySplitView.adjustSubviews();
}
override func splitView(splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
return proposedMinimumPosition + 200
}
}
I currently have a segue that presents a VC modally in PresentationStyle.PageSheet. I have done this both programmatically and with just the storyboard. I get the same result with both approaches, the modal pop over presents itself but does not show any content inside the UIView from the VC. It will only show the background color of the view and that is all. I also want to point out that everything is displayed if I do a default modal segue (full screen) but fails with page sheet presentation style or with using UIPopoverController. Here are some screen shots that show what I am talking about.
This is what it looks like in the storyboard:
This is what it looks like in the simulator and on an actual ipad:
Here is what my coding approach looked like:
#IBAction func addPickUp(){
var addPickupVC = self.storyboard?.instantiateViewControllerWithIdentifier("pickup") as AddPickupViewController
addPickupVC.modalPresentationStyle = UIModalPresentationStyle.PageSheet
self.presentViewController(addPickupVC, animated: true, completion: nil)
}
This written in swift for ipad ios8.
What am I missing here? Any constructive feed back is appreciated!
EDIT: Here is the document outline of the VC that is to presented modally.
Your code for presenting popover is correct.
Probably there is problem with AutoLayout constraints.
As you can see your popover is presented but label is missing.
Remove your AutoLayout (they will be auto generated) and see if the label will be visible now
Try to add new label. Drag and drop it, and don't specify any constraints
Debug your view
Click "Debug view hierarchy" button at the debug panel
Now you can see your view hearty. Select your label, if it's present and see it's constraints.
Check your AutoLayout constraints and Label is present in correct Size Classes
Size classes is shown bellow UI designer. In my case it's (Any Any).
It means that it's for all sizes and all devices.
Also check that your constrains is not removes at runtime.
You can see it on inspector in right side.
In the storyboard, you can simply control drag a connection from your button to your presented Viewcontroller. There's no reason to have a #IBAction for this. If you use the InterfaceBuilder approach you can optionally set the presentation style on the segue to PageSheet.