Posts

Post marked as solved
3 Replies
852 Views
Hi all,I'm sorry if this question has already been made.I'm writing a macOS app with Swift. This App is StoryBoard based and in the main Window there is an NSView where I do some graphics.Well, in the NSViewController associated I have implemented (overriden) the@IBAction func saveDocument(_ sender: Any?)@IBAction func openDocument(_ sender: Any?)in order to save and open data associated with my NSView (accessible from the NSViewController using an Outlet).In order to call the "print" action of my NSView object, I need to connect in some way the "Print" menu item to an action. I though it would have been enough as for the "save" and "open" to override the@IBAction func printDocument(_ sender: Any?)but nothing happes: when I push CMD-P or I select "Print" from the Main Menu, is always called the standard Print Dialog (I suppose the one definited for the First Responder).If I try to connect the NSMenuItem "Print" to a normal IBAction, the Action is not discovered by XCode but the funny thing is, if in my saveDocument or openDocument I invoke the print action of my NSView, the Print Panel is opened properly and I can print my content!!Can you please help me to achieve my goal of printing my NSView?Thanks in advance!!!
Posted
by getangar.
Last updated
.
Post not yet marked as solved
5 Replies
2.4k Views
Hi there,My task sounds simple: the goal is to call from the "draw" method of a custom class which extend an NSView another method who do calculation and then draws something in the view.override init(frame frameRect: NSRect) { // .. some code here self.drawMethod(rect: rect) // }here is the method used to draw my stuff:@objc func drawMethod(rect : CGRect) { let width = Double(rect.size.width) let height = Double(rect.size.height) // ... some code here for x in stride(from: 0, to: width, by: blockiness) { for y in stride(from: 0, to: height, by: blockiness) { // } } self.setNeedsDisplay(rect) }So far so good: the problem is that the content of the view is displayed after some secods while I would like to display an update each end of the inner for cicle.Coming from the .NET world, I would do just an "Application.DoEvents()"How can I achieve here the same result?Forgot ... I'm using (learning) Swift 5 and the target is macOS current version :-)
Posted
by getangar.
Last updated
.