« Q&A: April 03, 2001

Posted by Andy Monitzer on April 03, 2001 [Feedback (0) & TrackBack (0)]

// Question One

I'm using IB/PB Cocoa to build an application. What is the best way to put a picture (.tiff .gif or .jpeg) as the background of a window and still have other controls on the window work?

Answers

Unless you want a "borderless" window, I'd just put create an NSImageView that covers the interior of the window, and put everything else on top of that.

answer by: John Hörnkvist

The AppKit does really handle overlapping views and the various optimizations may give unexpected rendering results. What you want to do is replace the content view of the window with a custom view which draws the image. It could be an NSImageView or one that implements it's own -[NSView drawRect:] method.
See -[NSWindow setContentView:].

answer by: Andrew Platzer


// Question Two

How do you create a NSRange object?

Answer

NSRange is a structure...

typedef struct _NSRange {
    unsigned int location;
    unsigned int length;
} NSRange;

so to create an NSRange:

unsigned int location,length;
...
NSRange range = {location, length};

or

range.location = x;
range.length = y;

answer by: Eric Weiss


// Question Three

Is it possible to define a pair of classes which have circular dependancies in their static types?

I have two classes, one called File and a subclass called Dir. The File object contains a reference to a Dir instance, (the directory that contains it).

Do I have to use "id" rather than the static types to make this compile?

// File.h
#import "Dir.h";
@interface File : NSObject {
    Dir *dir;
}
@end

// Dir.h
#import "File.h"
@interface Dir : File {
    Dir *parent;
}
@end

Answer

You can't define a subclass of a class you haven't defined yet, which you're attempting to do via the #import of Dir.h.

Instead it's probably best to put a @class Dir there to let the compiler know that Dir exists but you'll define it later. You're correct that you could also use id, but you don't have to. You could also declare a Dir protocol and declare File's ivar as "id <Dir> *dir;" if you want, but @class is really the simplest solution here.

answer by: Rick Roe


// Question Four

Is it possible to have a nib which contains views not contained in a window?

Answer

Yes, drag a CustomView from the palette into the document and then work on it as normal.

answer by: Vince DeMarco


// Question Five

I am not able to open a window which I closed using [myWindow close];...

Answer

Don't use close, it will dealloc the window. For hiding windows, use [myWindow orderOut:nil];.

answer by: Andreas Monitzer


// Question Six

Does anyone know how to package apps in .dmg format?

Answer

Here is a sample session.

> hdiutil create -megabytes 20 Foo.dmg<- creates a 20 Meg Foo.dmg. This is read-write.
> hdid -nomount Foo.dmg<- will mount the image, but not tell the system, trust me you want -nomount
> sudo newfs_hfs /dev/disk#<- the number is given at the end of the previous commmand
> hdiutil eject /dev/disk#<- eject it
> hdid Foo.dmg<- mount it editable
Now use the finder to put the files in the image and rename the volume from untitled
when finished eject the image

> hdiutil convert -format UDCO Foo.dmg -o FinalNameYouwant.dmg -noext

You should end up with a compressed dmg that is suitable for the internet.

answer by: Eric Peyton


// Question Seven

Does anyone know the plist keys to make a faceless background application?

Answer

You can set NSUIElement in the Info.plist to 1. That'll give you a dock-like effect, where you can still display windows and other UI but it'll be impossible to bring your app to the front.

answer by: Tim Omernick


Comments
Post a comment