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.
Related
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.
I have a toolbar on my macOS app, developed in Swift. The toolbarItem is dragable onto the NSWindowController, and I can setup an IABAction function, I just have a print in the function at the moment. And when I click on the button nothing happen the click does not seem to be recognised as an action ?
I had a few more line of code in the function but deleted it and now have just the print("test") line.
#IBAction func exportCsvClicked(_ sender: NSToolbarItem) {
print("test") }
No output observed, so I'd love to get "test" in the console when I click on this button.
Here is a list of the connections associated with the toolbarItem.
I found a way to get around the fact that the IBAction from an NSToolbarItem does not recognise the click on this item:
1/I made a customSegue from the item to the main window controller (it can go anywhere)
2/The prepare for segue function posts a notification to the notification saying that the item has been clicked.
3/The main view controller observes the notification and presents, either has a popup or a sheet (I got two buttons), the view that I have setup in the storyboard (referencing with the storyboardID). I found that you need to pass on all the necessary variable to setup the view from the main view Controller, and that there was issue of code in the viewDidLoad function of the sheet/popup view not running, I am suspecting that they might be different instances.
I am creating an app that requires notifications. I created a settings page with a switch to toggle notifications for the application. I tried to link the switch to ViewController2 using an #IBAction, but it keeps connecting the object to Exit, instead of ViewController. I am getting really frustrated because the #IBAction won't stay connected. I am not sure what is going on, but if I could get help that would be amazing.
The images are linked down below to Imigur.
This is the connection to ViewController2
This is what occurs when I connect the IBAction to ViewController2
You can see there is no action option for the connection in this image.
When you attach #IBActions (or #IBOutlets), you do not want to attach them to Exit on the View Controller.
Follow these steps to add an #IBAction:
1) Make sure your View Controller's class is linked to your file, then go into the Assistant Editor making sure you selected Automatic.
2) Hold Control (^) and drag the button to your ViewController class.
3) Add the button as an #IBAction. - It's also recommended to use UIButton as the sender, instead of Any.
It should look like this:
If you have questions, let me know!
The problem might be that you are supposing you can form an action connection from a UISwitch in the scene of one view controller to a different view controller. You can't. You can form outlets and actions only between a view controller and the interface inside the same scene of the storyboard.
Click on the top bar of your problematic ViewController (the overview of what is getting displayed on screen), click the top left icon (called View Controller).
On the right click "Show The Identity Inspector" icon and you should see class. Change the text to 'ViewController'. Hopefully it should auto fill.
This will solve the problem.
I am trying to put a website in the middle of my storyboard. When I add the view controller and try to connect it to a new ViewController, I cannot control-drag the object to create the Outlet. I can create outlets for Labels and buttons, and all the rest of the normal objects. Just not for the webkit view control. It works if I try it in a new project just like it is supposed to. Is this a bug or is something in my program blocking web content?
There is no code to share since I can't get that far.
I understood your problem. Such kind of thing sometimes happen with me.
I uses a one tick to solve this problem. I copy the outlet of other control and then i rename it and change the property to my requirement.
For Example,
#IBOutlet weak var myButton: UIButton!
After then you can connect outlets to your control.
It works fine.
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
}
}