Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Interface Builder - Changing Class Identity - fail

I had an NSView set up as the view for my NSCollectionViewItem and had placed a number of sub objects on it (text fields, checkboxes, labels, and the like) when I decided I really wanted an NSBox instead of an NSView.

I tried changing the Class Identity to NSBox, but the Interface Builder continued to interpret the view as an NSView (not showing NSBox settings like title and such).

In the end, I just created a new NSBox and dragged my elements over from my original (I was very pleased to see they retained their links!).

Sooo, my question is: should I have been able to just change the class of my view to NSBox with a simple entry change in Class Identity? If so, any ideas what might have went wrong?

Thanks,

Agathon

p.s. I noticed that when I selected NSBox in Class Identity, the font remained dark, but If I chose another class, the font appeared gray. The same display in my new NSBox is gray as well. I'm suspecting the Interface Builder somehow got convinced that "NSBox" was a custom class and that was blocking my selection of the real NSBox.

Mac Pro, Mac OS X (10.5.6)

Posted on May 4, 2009 1:10 PM

Reply
7 replies

May 4, 2009 11:27 PM in response to Agathon

Generally you can't expect to change the class of an object in the Identity Inspector and then get the Attributes or Size Inspector panels appropriate to the new class (the icon for the object won't change either). The Connections inspector will track the change though.

The Identity Inspector also doesn't like to change an object to a class that's not a child of the current class, though it seems some objects are more flexible than others.

I think of the Id panel's Class field as a way to set a custom subclass or to make an object that isn't in the library. I don't think it's intended as a convenient way to convert an object to a different library object after i've changed my mind.

May 6, 2009 7:13 PM in response to RayNewbie

Thanks. No problem, go for it.

This part "The Identity Inspector also doesn't like to change an object to a class that's not a child of the current class, though it seems some objects are more flexible than others." was key though, and I didn't duplicate that.

The way it works is that the object has it's original/design-time class, and it's runtime class. When you use the identity inspector, your setting the runtime class. You can set to runtime class to any class that's a descendent of the original class.

Nov 7, 2009 7:25 PM in response to Jon Hess

I am having a similar problem to the OP. I had my NSCollectionViewItem as a NSView and then changed it to a NSBox in the Class Identity box. I understand what you are saying when you refer to IB not following the class type precisely in the Identity Inspector. This is due to the Dynamic Creation pattern IB follows at runtime. Since IB really doesn't know of these "other" types it sticks with NSView (something it knows).

However my problem is at runtime. When I run the code the following awakeFromNib is run by my subclass of NSCollectionViewItem. A view is returned and casted as a NSBox* but when I look at the class type (the NSLog line below) it returns as a NSView type. Then the next line (setTitlePosition method called) crashes because it doesn't exist.


@Interface CollectionViewItem : NSCollectionViewItem {
...
}
#Import "CollectionViewItem.h"
@Implementation CollectionViewItem
{
...
-(void)awakeFromNib{
NSBox *box = (NSBox *)[self view];
NSLog(@"The view type is %@", [box class]);
[box setTitlePosition:NSNoTitle];
[box setBoxType:NSBoxCustom];
[box setCornerRadius:8.0];
[box setBorderType:NSLineBorder];
}
...
}


So basically I have two questions:
1) Why is the NSCollectionViewItem view method not returning the NSBox as it is configured in the Class Identity?

2) Why is the cast to NSBox not crashing?

Any help will be greatly appreciated.

Rob

Interface Builder - Changing Class Identity - fail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.