Open Library > Container View. If you use that, it creates that View Controller.
In any case, I tried both ways with the same result.
Post
Replies
Boosts
Views
Activity
Here is an example with macOS:
When you say "5. you can keep the content layout and frame layout ON", what do you mean?
I have opened a new thread. I have been searching and trying things but still, I do not understand your sketch solution. Are you sure this is macOS and storyboards? It looks very new to me and I do not know how to learn.
These are some of the things I tried:
var controller: NSWindowController?
@IBAction func loadSecondFromMenu(_ sender: NSButton) {
let storyboard: NSStoryboard = NSStoryboard(name: "Main", bundle: nil)
let myViewController = storyboard.instantiateController(withIdentifier: "SecondView") as? SecondViewController
//self.view.window?.contentViewController = myViewController //error: Value of type 'AppDelegate' has no member 'view'
//controller?.contentViewController = myViewController //no error, and it does not open any window
}
I have a window controller and two views. With my code, I open view1. I try to open view2 with code.
I do not understand your code. It gives me error.
That is just fantastic!
I have been hours searching and trying things and you solved in a minute!. Thank you!
I want to animate (using any method) the change of the label's text in a macOS app.
With the code I provide, the change occurs when I click the button. I see no animation and no delay.
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var label1: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func button2(_ sender: NSButton) {
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 4.0
label1.stringValue = "long, long text"
label1.animator().sizeToFit()
})
}
}
This works very well. Thank you!
.cursor: NSCursor.pointingHand
I did not notice that I had the wrong Outlet. It seems that only happens with macOS. in iOS I did not had that problem. Thank you!
Do you know how to change the cursor on hover the link?
Sorry, I meant window size. (I do not see how to edit the question and correct that error)
Thank you for your answer.
What do you mean by pages (I have two pages) ?
I have two View Controllers in storyboard and two files for the code: ViewController.swift and Preferences.swift. They are connected in the Identity inspector.
Please show code that will be easier to explain.
In a simplified version, there is no code yet. I just put a button on the View Controller - Preferences of the Storyboard
If I do not make subclass I think I should:var webView: WKWebView!If I do that the code works well to make a webview with code if I begin a new project. To repair the projects with the old code just write that new code does not seem to work. Even then I make Product > Clean Built Folder.
This code gives me the same problem:import Cocoa
import WebKit
class ViewController: NSViewController, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.apple.com")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}
}
I have other macOS and iOS projects with the exact same code and still now they work well. I do not know why I cannot do any new one.Signing & Capabilities > Outgoing Connections (Client)ViewController.swift:import Cocoa
import WebKit
class ViewController: NSViewController {
let webView = WKWebView()
override func loadView() {
self.view = webView
if let url = URL(string: "https://www.apple.com") {
let request = URLRequest(url: url)
webView.load(request)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}