Interface Builder Not Seeing Outlets with MACruby

MacRuby + Interface Builder: How to display, then close, then display a window again

The issue is that it doesn't create the window each time. Release on close is a bit of an annoying option and generally is only used if you know the window controller is also being released when the window closes. (Note I've never used MacRuby so I'll be giving code in Obj-C as I know that it is correct, hopefully you can convert it. I'll be assuming GC is on as it should be with MacRuby).

Now there are two ways to do this. I'm not entirely sure how your NIB/classes are set up as it could be one of two ways.

--

The first way to solve it is to use the outlets you use to reference the form elements to blank them out when you display the window again eg [myTextField setStringValue:@""]. If you're using cocoa bindings then it's a little trickier, but basically you have to make sure the bound object is blanked out. I would recommend against bindings though if you are new to Cocoa.

--

The second way is to make the AddNewAccountController class a subclass of NSWindowController. When you press the + button you would then create a new instance of it and display it (remember to store it in an ivar). The best way to do it would be as so:

if (!addAccountController) {
addAccountController = [[AddNewAccountController alloc] initWithWindowNibName:@"AddNewAccountController"];
[[addAccountController window] setDelegate:self];
}
[addAccountController showWindow:self];

This prevents a new instance being made if the window is already visible. You then need to implement the delegate:

- (void)windowWillClose:(NSNotification *)notification {
//If you don't create the account in the AddNewAccountController then do it here
addAccountController = nil;
}

Obviously you would need to move the window to a separate NIB called "AddNewAccountController". In this NIB make sure to set the class of the File's Owner to AddNewAccountController and then to connect the File's Owner's window outlet to the window.

When all this is set up, you will get a fresh controller/window each time. It also has the benefit of splitting up nibs and controllers into more focused units.

--

One last thing. While it is fine to do something like this in a window, you may want to eventually look at doing this via a sheet, as it would then prevent the possibility of the add account window getting hidden behind other windows.

Adding outlets to Object in Interface Builder in Xcode 3.2.3

It looks like you are using an older version of xCode. I recommend you upgrade to the latest version 4.6.

On the older version, you need to pick the template "View-based application" and not "Window-Based application.

Hope this helps.

How to define Outlets and Actions in the Classes Pane in Interface Builder in Xcode 4?

This does appear to be removed from Xcode 4, but there isn't much need for it anymore since Xcode 4 integrates the editor directly with IB. The feature never really worked that well in Xcode 3 IMO anyway.

In Xcode 4, display the header for your object by selecting your object and View>Editors>Assistant. Now control-drag from the object you want to connect into the header. This will let you automatically create an outlet or action and bind it all at once.

See the Xcode 4 Transition Guide for more information.

MacRuby Accessing/Updating Text Fields

Figured out what was going on. Within the setMessageField method, the += operator was not valid. So I had to change it to the following. I changed the method name btw.

attr_accessor :window
attr_accessor :subjectField, :messageField, :emailTo, :emailFrom, :smtpServerAddress, :smtpPort, :password

def setText(sender)
@messageField.stringValue = "SMTP Server Address: #{@smtpServerAddress.stringValue}\n"
@messageField.stringValue = "#{@messageField.stringValue}SMTP Port: #{@smtpPort.stringValue}\n"
@messageField.stringValue = "#{@messageField.stringValue}User Email: #{@emailFrom.stringValue}\n"
@messageField.stringValue = "#{@messageField.stringValue}User Password: #{@password.stringValue}\n"
@messageField.stringValue = "#{@messageField.stringValue}To Email: #{@emailTo.stringValue}"
@messageField.stringValue = "#{@messageField.stringValue}Subject: #{@subjectField.stringValue}\n"
end

Works like a charm now.

Cocoa/MacRuby: How to write a toolbar which accepts custom items?

There is an excellent tutorial here: http://www.mere-mortal-software.com/blog/details.php?d=2007-03-14

It is targeted at preferences windows, but of course you could use the window class anywhere.

I have not bothered to port the window superclass to Macruby, I just use it as is. Then I use macruby to write the subclass, for example:

class MopenPrefsWindowController < DBPrefsWindowController
attr_accessor :generalPrefsView
attr_accessor :openingPrefsView
attr_accessor :advancedPrefsView
attr_accessor :appearancePrefsView

def setupToolbar
self.addView(generalPrefsView, label:"General", image:NSImage.imageNamed(NSImageNamePreferencesGeneral))
self.addView(openingPrefsView, label:"Opening")
self.addView(advancedPrefsView, label:"Advanced", image:NSImage.imageNamed(NSImageNameAdvanced))
self.addView(appearancePrefsView, label:"Appearance")
end
end

The one thing that might cause me to some day port the window class to macruby is to give it the ability to have a bottom section that appears on all panes.

Cocoa controller question

Declare the second window controller as an instance variable of your app controller and make it a property. Then you can easily send messages to it's IBOutlets (provided they are also properties) via the appDelegate.

Let's say you're going to have window A send window B a message. In Window A's controller you might have a method like this:

- (IBAction)messageWindowB:(id)sender {

myAppDelegate *appDelegate = [NSApplication sharedApplication] delegate];
[appDelegate.windowB.theView doSomething];

}

Honestly, I am not sure if I entirely understood your question. Also, this is a quick and dirty approach. So if anyone else has suggestions, please be my guest!



Related Topics



Leave a reply



Submit