Swift storyboards: split view controller not showing properly on MacOS - swift

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
}
}

Related

Making Inspector Sidebar in macOS Window

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.

How do I to create a custom navigation bar for NSTabViewController in Swift 4

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.

Update text field values in multiple tabs with single button

I have 6 tabs in my application.
Each tab has a text field.
There is one button in the sixth tab, which when pressed, should reset the text fields in all the other 5 tabs to blank.
I am unable to figure out any direction in which I should look.
I am pretty new to Xcode, so please pardon my ignorance on this topic.
One thing I have tried so far is to set global variable.
When I press the button, I update the global variable to ""
But then I go to the other tabs, the value has not been updated.
My understanding is that I an not writing the code in the right place.
Currently, I have written this code in viewDidLoad function of each tab's viewController class:
override func viewDidLoad() {
super.viewDidLoad()
telephone.text = ViewLine.GlobalVariable.phone1
timerData.text = ViewLine.GlobalVariable.concept1
}
phone1 and concept1 are my global variables.
Would anyone be able to suggest where should I write this code? or is there a better way to do this?
Thanks
Write code in viewWillAppear
override func viewWillAppear() {
super.viewWillAppear()
telephone.text = ViewLine.GlobalVariable.phone1
timerData.text = ViewLine.GlobalVariable.concept1
}
I think that what you want is the first 5 view controllers to react to a tap on a button in the 6th view controller.
In that case - don't use global variables.
Use notifications:
When the button did tap, send a notification. The first 5 view controllers should subscribe to this notification channel. When each of the first 5 view controllers receive a notification they should change the text to "".
Here is a link on notifications:
https://www.raywenderlich.com/160653/design-patterns-ios-using-swift-part-22

Automatic preview will not show View Controller code

I am in Xcode 6 and the view controller code was showing up under the automatic preview: now it is gone.
You cannot hook up the text fields under manual when selected. Where did it go, and how do I get it back? I have to keep deleting the VC and making new ones. is this a problem with Swift? I don't won't to have to keep deleting 10 VC and redoing them to code.
It's not a problem with Swift; based on your answer, this may not be your problem, but you may not have your view controller file connected to your view in the storyboard (I am led to believe this by the fact that you have had to delete and re-add the file over and over again).
First, make sure that you've selected the view:
Then, open the Inspector menu and go to the Identity section:
Under "Custom Class," make sure that "Class" is the name of your class in your VC file (see below): it should auto-complete as you type it in.
Then, in your view controller file, make sure that you have defined the class name properly, like this:
class ViewController: UIViewController {
// VC code
}
This is not the answer but i had to type the #IBOutlet var firstNameTextField: UITextField! into the code under the manual preview instead of deleting the VC.swift. I then added a button and typed the #IBAction func savePointOfContactToDefault(sender: AnyObject){} and drag it to the button and the automatic preview now shows the code and you can now drag text, label, ect to the code. Ya seems to be a workaround.

UIModalPresentationStyle.PageSheet does not display ViewController content

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.