Re: New to Cocoa, needs help understanding various topics (delegates, connections in Interface Builder, ect...)
site_archiver@lists.apple.com Delivered-To: Cocoa-dev@lists.apple.com User-agent: Microsoft-Entourage/11.0.0.040405 In the case of setAspectRatio: it's a method of an instance of NSWindow that you want to call, to set the ratio. There is no need to use a delegate or a subclass. The following line executed by your program will set the aspect ratio for your main window. [[NSApp mainWindow] setAspectRatio:NSMakeSize(1.0,2.0)]; How does that work, where do you call it and how do you do it for your small window? Every program should have a controller. (The apple help has detailed explanation on this subject and there are a number of websites with good tutorials you should walk-through: file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Conceptual/C ocoaFundamentals/index.html?file:/Developer/ADC%20Reference%20Library/docume ntation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/chapter_5_sec tion_1.html Not knowing where to establish your connection I think is the crux of your question and you should read this guide from start to finish.) Solving the window aspect ratio would go something like this: 1. You create an IBOutlet in the controller class to yourSmallWindow. 2. You connect it by holding down ctrl and dragging from the controller to the window in Interface Builder and double clicking yourSmallWindow. (You have just connected the IBOutlet yourSmallWindow to the window.) 3. Whenever in your code you call your window to the front you can add the line: [yourSmallWindow setAspectRatio:NSMakeSize(1.0,2.0)]; to set the ratio. Since you asked about delegation. Delegation is just letting an object respond to delegate methods from another object. The NSApplication, who is the owner of your main nib file, has a number of delegate methods. One of which is -(void)applicationDidFinishLaunching:(NSNotification *)aNotification. Which you can use to set the aspect ratio of yourSmallWindow at launch? 1. In IB (Interface Builder) connect File Owner to your controller and double click on delegate. You just made the controller the delegate of NSApplication, if you implement any of the delegate methods of NSApplication in your controller then you will receive them and be able to add behaviour. 2. In your controller .m implementation file add this method: -(void)applicationDidFinishLaunching:(NSNotification *)aNotification { [yourSmallWindow setAspectRatio:NSMakeSize(1.0,2.0)]; } So now when NSApplication is done launching it send the controller the delegate method applicationDidFinishLaunching: which runs the setAspectRatio: on yourSmallWindow at startup. Be sure to use the included help in Xcode as well as cocoadev.com cocoadevcentral.com and cocoabuilder.com to search the list archives. This kind of broad questions you should be able to find answers on your own. As a beginner of Xcode and Objective-C it can be hard to understand certain concepts; so do write to the list but be very specific with what part of the documentation your having trouble with and what paragraph or sentence your not grasping. Conor http://www.bruji.com/ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... This email sent to site_archiver@lists.apple.com
participants (1)
-
Conor