I have following problem:
I try to build a small MenuBar App for MacOs. It is xib based and the main app is a MainMenu. From one of the menuItems I try to open a new NSWindow. I made a SecondViewController.swift with its generated SecondViewController.xib.
Simple View with one button:
View of NSWindow as xib
SecondViewController.swift
Source Code
The button title changes to "ROFL", but when the button is pressed nothing happens. Cann someone explain this to me?
Here the controller is created:
Init code of Controller
Related
OS: MacOS
language: Swift 4+
What I want
I want to show a simple custom modal view from my main window. This custom modal view I created in a separate .xib file with belonging NSWindowController class.
In Xcode I added a new file --> CocoaClass --> Subclass of NSWindowController --> Checkmarked "Also create XIB file for user interface"
I than added a button and generated an action handler that simply prints text on the debug console. This to test whether the button press is correctly handled or not.
To show the modal view from my main window I have the following code executed when a button has pressed:
let modal = SimpleModal(windowNibName: "SimpleModal")
self.view.window?.beginSheet(modal.window!, completionHandler: { response in
print("Finished device selection")
})
This does show the view, but not as a modal view. It simply shows the view next to my main window and the modal view also doesn't react on mouse click events, when I click on the button in the modal view.
I don't know how to get this right, so if you know how to do this, please answer me.
NOTE:
When modal view shows up, the main window should be unresponsive until the user dismisses the modal view. It's like moving the focus from main window to the modal view.
The source of my demo project:
OSXModalView
You have to remove the Visible At Launch flag in the attribute inspector of your window object in SimpleModal.xib. Otherwise your code works.
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 have little problem with my app. On main ViewController i have embbed Container View with objective-C chart.
I have 2 buttons and always when i press it i need update this UIView. Everything like setNeedsDisplay() not working.
But when i go to another ViewController and going back, my chart is updated.
Here is my main controller:
By buttons i go to previous year and data not updated.
But going to Another ViewController and:
Booom data updated. Im trying methods like: IBAction when button is pressed call function setNeedsDisplay() for self or view.
Thanks for your time! PS: Its not table, its CONTAINER VIEW.
Here is my project tree:
TREE
and i have container view to embbed this:
view
So i just need refresh UIViewController when i press button. Doesnt have any conection with objective-c to swift code (just one string array).
I am new to swift / Xcode and I am trying to create a button in Xcode that can randomly transfer to a different storyboard. I tried following the instructions in this post to do it (I also tried other ideas, but this answer was the most intuitive)
How to Segue Randomly to ViewControllers in Swift?
I've written the IBAction and connected the extra storyboards with different segues to the root view controller but when I start the simulation nothing happens when I click the "go" button. I cannot connect this button with the IBAction by a control drag, so I think that may be the problem.
I've tried creating new projects, connecting the "go" button to the root view controller, and editing the classes (it doesn't let me). What else could be wrong? My code is exactly like the answer to the link I posted. Is there a step missing to that answer?
First make sure you created a custom class for your root view controller. Also make sure you assigned your custom class to the view controller in Interface Builder.
Try dragging from your button to the view controller code pane and let XCode create the IBAction stub for you. Now touching the button should trigger your IBAction.
I have created a simple app using storyboard. In storyboard file, i have dragged one view controller. I want to assign a class to the newly added view controller. To do this, I clicked on new file in Xcode, clicked on Objective c class, entered class name MyViewController and subclass is of UIViewController. I went back to storyboard and clicked on Custom class type and given MyViewController in class tab. But it is not taking this. If i unselect the viewcontroller and select, custom class shows "UIView" again.
I am using Xcode version 4.3.3 (4E3002).
xcode does this problem even if everything is fine. Close your xcode project and then quit xcode. Start again and you will be able to find the class in the dropdown menu.