views:

370

answers:

1

I'm working on my first major Cocoa app for an undergraduate research project.

The application is document-based and uses Core Data. One of the entities is an abstract entity, Page. Page is parent of several types of pages: ie PageWithHeaderAndFooter, PageWithTwoColumns, BasicPage etc. Page has attributes, such as title and author, that all pages have in common. Each specific type of page has a certain number of layout blocks (PageWithHeaderAndFooter has three: header, footer, body. BasicPage has one: body. etc.) Additionally, all Page subclasses define layout-specific implementations of certain methods.

The other relevant entity is Style, which defines the visual look of a Page. (Think of Pages as HTML and Style as CSS.)

I would like my app to have an iTunes/Mail-like source list with sections. (One section would be Pages, the other would be Styles.) I have a pretty good idea how to do the sectioned source list (this was a great help).

However, after hours of headbanging and fruitless googling, here's what I can't figure out:

Pages and Styles listed in the source list, and when you select one of them, all of the relevant fields for that object appear at the right (mostly NSTextViews, pop up menus, etc).

I laid that out and did all of the bindings in Interface Builder.

The problem is, if my source list contains different types of pages, how do I get a different view to display at the right depending on the type of page selected? For example, if a BasicPage is selected, I want just what you see above: the general page stuff and one NSTextView that corresponds to the one field body of BasicPage. But if I select a PageWithHeaderAndFooter, I want to display the general page stuff plus three NSTextViews (one for header, body, and footer.) If I have a Style selected, I want to display various pop up menus, color wells, etc.

For the pages at least, we're only talking about one or more NSTextViews, each of which corresponds to a String attribute of the respective entity.

How would you do this?

Thank you for your help!

+1  A: 

I have a list of items which are one of 3 types, all are very similar however.

I set the Entity into the view controller before I push it, then in viewDidLoad of the pushee I check what type of entity I have and layout the information differently by specifying different nibs to load.

if([[entity entityType] isEqualToString:@"TypeA"]) {
    [[NSBundle mainBundle] loadNibNamed:@"TypeAView" owner:self options:nil];
} else if(...) { .....

This works just fine, for me.

michael