I was wondering if anyone could tell me if there is a method in Cocoa that will display information (images) on screen when a button is pressed. What I mean is NSLog
"prints text" to the console is there a method that displays images just as easily like would -(void)drawView
do it? Is it just setNeedsDisplay
? I hope this makes sense. I am essentially wanting to know if I can call something that will display an image as easily as you can display/print text to the screen/console.
views:
52answers:
2You should take a look at Apple's NSImageView Class Reference.
This a class you can use to display an image in Cocoa.
setNeedsDisplay
is a NSView method that tells the graphics renderer it needs to redraw the image because the data has been modified. Presumably because you are using something like Quartz and you have called some custom drawing code. If you are drawing bitmap images then you probably won't need to use this.
The Console is text-only, so no, you can't print an image to it the same way you log text. The closest equivalent is to export the image as TIFF data and write that data to a file in the temporary directory.
As for setNeedsDisplay:
, that tells AppKit that the view should be told to redraw the next time the window redraws its views. (In other words, it sets the view as needing display—exactly what it says on the box.) Usually, this is because you've changed the model object(s) that the view displays, either by replacing them with other objects or by mutating one or more of their properties.
You would need to have a view to display; an image view would certainly qualify, but if you're looking for the image equivalent to NSLog
, this isn't it, unless you don't mind either making a dedicated window just for showing this image or temporarily putting a image view into one of your real windows.