<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>KATI</title>
	<atom:link href="http://katidev.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://katidev.com/blog</link>
	<description>Developing Interfaces with Cocoa</description>
	<pubDate>Thu, 04 Jun 2009 10:13:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Gameboards and GUIs</title>
		<link>http://katidev.com/blog/2009/06/04/gameboards-and-guis/</link>
		<comments>http://katidev.com/blog/2009/06/04/gameboards-and-guis/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 09:56:09 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=208</guid>
		<description><![CDATA[
I wrote a post for the Sofa blog called Gameboards and GUIs.  It&#8217;s inspired by something I read in the game design book, Rules of Play, by Katie Salen and Eric Zimmerman and I want to take a moment here to recommend the book to anyone who&#8217;s interested in interface and interaction design.  [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2009/06/0cc09a14-d655-4e2d-bff2-d6fd1ad430aa.jpg" alt="0CC09A14-D655-4E2D-BFF2-D6FD1AD430AA.jpg" border="0" width="386" height="475" /></div>
<p>I wrote a post for the Sofa blog called<a href="http://www.madebysofa.com/#blog/GameboardsAndGUIs"> Gameboards and GUIs</a>.  It&#8217;s inspired by something I read in the game design book, <a href="http://www.amazon.com/Rules-Play-Game-Design-Fundamentals/dp/0262240459/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1243940889&#038;sr=8-1">Rules of Play</a>, by Katie Salen and Eric Zimmerman and I want to take a moment here to recommend the book to anyone who&#8217;s interested in interface and interaction design.  It&#8217;s a great book with unique insight into the challenge of engaging people in meaningful and enjoyable experiences.  Add it to <em>your</em> reading rainbow!</p>
<p><a href="http://www.madebysofa.com/#blog/GameboardsAndGUIs">Gameboards and GUIs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2009/06/04/gameboards-and-guis/feed/</wfw:commentRss>
		</item>
		<item>
		<title>KTUIKit 0.9.1</title>
		<link>http://katidev.com/blog/2009/05/26/ktuikit-091/</link>
		<comments>http://katidev.com/blog/2009/05/26/ktuikit-091/#comments</comments>
		<pubDate>Tue, 26 May 2009 13:09:42 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=202</guid>
		<description><![CDATA[I want to thank all of the brave Mac devs out there who&#8217;ve taken the time to try out KTUIKit.  The comments and bug reports are extremely helful and appreciated.  Thank you.
Things have been moving along with KTUIKit and I&#8217;m finally ready for a new Pre-alpha milestone release (0.9.1).  
You can download [...]]]></description>
			<content:encoded><![CDATA[<p>I want to thank all of the brave Mac devs out there who&#8217;ve taken the time to try out KTUIKit.  The comments and bug reports are extremely helful and appreciated.  Thank you.</p>
<p>Things have been moving along with KTUIKit and I&#8217;m finally ready for a new Pre-alpha milestone release (0.9.1).  </p>
<p>You can download a copy of the release <a href="http://katidev.com/blog/wp-content/uploads/2009/05/ktuikit-091.zip" title="KTUIKit 0.9.1.zip">here</a>, or checkout the source from the  <a href="http://code.google.com/p/ktuikit/source/checkout">GoogleCode project</a>.</p>
<p>The .zip file contains:</p>
<li>A build of the framework</li>
<li>A build of the plugin</li>
<li>The KTUIKit Xcode project</li>
<li>An example application Xcode project that uses the framework and plugin</li>
<p>I&#8217;ve posted the release notes on the project&#8217;s <a href="http://code.google.com/p/ktuikit/">home page</a>.  There are major API changes in this update so I&#8217;ve made the previous revision of the project available for <a href="http://katidev.com/blog/wp-content/uploads/2009/05/ktuikit-source-0901.zip" title="KTUIKit_Source_0.9.0.zip">download</a> for those who went beyond &#8216;brave&#8217; into the realm of &#8216;crazy&#8217; and have used it in a project you actually care about <img src='http://katidev.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I&#8217;ve also updated the <a href="http://katidev.com/blog/ktuikit/">KTUIKit page</a> here on the blog with new instructions on how to install the plugin and use the framework in a project.  The example project on the page has also been updated to use the latest version of the plugin and framework.  </p>
<p>A little bit of news:  I started working at <a href="http://www.madebysofa.com/">Sofa</a> a few months back and we&#8217;re using KTUIKit in a new product. I&#8217;m developing KTUIKit for Sofa in a separate branch of the subversion project and will slowly move those changes over to the trunk as the designs are finalized and the code stabilized.  There are two things that made it into this version of the trunk that some people might find interesting:  <strong>KTLayerController</strong>, a new controller for layers (like a view controller is to views) and <strong>KTTabViewController</strong>, whose only job is to switch between a list of view controllers.  Both are still *in the works*, but I&#8217;ve been using them and I think they have promise.  I have very loose descriptions of the classes and more in the release notes.</p>
<p>Again, thanks to everyone and I&#8217;ll see you at WWDC!</p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2009/05/26/ktuikit-091/feed/</wfw:commentRss>
		</item>
		<item>
		<title>KTUIKit 0.9.0</title>
		<link>http://katidev.com/blog/2008/11/12/ktuikit-090/</link>
		<comments>http://katidev.com/blog/2008/11/12/ktuikit-090/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 21:21:54 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[KTUIKit]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=171</guid>
		<description><![CDATA[I&#8217;m pleased to (finally!) introduce KTUIKit, an open source framework and Interface Builder plug-in project.  The goal of the project is to address some of the issues that I&#8217;ve brought up in previous posts on this blog:
Incorporating NSViewController into Cocoa&#8217;s controller system
Replacing NSView&#8217;s Autoresizing mechanism for the layout of views and controls
Styling of views [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pleased to (finally!) introduce <a href="http://katidev.com/blog/ktuikit/">KTUIKit</a>, an open source framework and Interface Builder plug-in project.  The goal of the project is to address some of the issues that I&#8217;ve brought up in previous posts on this blog:</p>
<li>Incorporating NSViewController into Cocoa&#8217;s controller system</li>
<li>Replacing NSView&#8217;s Autoresizing mechanism for the layout of views and controls</li>
<li>Styling of views (not controls, i wish&#8230;)</li>
<p>KTUIKit currently includes the XS-Controllers, KTView, subclasses of many of the standard Cocoa controls, KTLayoutManager and KTStyleManager.  The Interface Builder plug-in provides a GUI for the layout manager and style manager.  </p>
<p><strong>This is still very much a work-in-progress. Don&#8217;t try to use it in your own project yet!</strong>  There are bugs - especially in the Interface Builder &#8216;Style&#8217; inspector, which is basically still unusable for anyone other than the person that programmed it&#8230;  Nevertheless, I thought I&#8217;d go ahead and put the project out there - incomplete, with bugs and all.  </p>
<p>If you want to check it out in action, you can download an <a href="http://katidev.com/blog/wp-content/uploads/2008/11/ktuikit-090-example.zip" title="KTUIKit_0.9.0_Example.zip">example project</a>.  The project shows how to use the layout and style managers in the view controller classes as well as in Interface Builder. If you want to open the nib files, you&#8217;ll have to do a little bit of work to get Interface Builder to load the plug-in:</p>
<li>Build the KTUIKit Xcode project that came with the example project</li>
<li>Copy the framework, which is located in a directory called &#8220;Uninstalled Products&#8221; in the Xcode project&#8217;s build directory, into your ~Library/Frameworks directory</li>
<li>Launch Interface Builder and go to its Preferences window</li>
<li>Go to the &#8220;Plug-ins&#8221; tab and hit the Add (+) button</li>
<li>Navigate IB to the copy of the framework in your ~Library/Frameworks directory</li>
<li>Hit &#8216;Open&#8217;</li>
<li>KATI will show up in your list of plug-ins and its library objects will show up in your library.</li>
<h3>The Example Project</h3>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/11/exampleapp.jpg" alt="ExampleApp.jpg" border="0" width="450" height="303" /></div>
<p>This example is very similar to the view controller example projects I&#8217;ve posted in the past.  It&#8217;s basically a window composed of several nib files, pieced together by several view controllers.  The difference is that it uses KTUIKit&#8217;s views and their layout and style managers.  </p>
<p>The main thing to notice is how durable the layout is.  Make the window as small as you can and as big as you can - drag the split view dividers all the way to zero and back.  Nothing breaks. Everything is where it should be.  There are also examples in the code of using the layout manager&#8217;s relative layout configurations - like &#8220;filling&#8221; and &#8220;floating&#8221;. There is no extra layout calculation code in the view controllers and KTView is never subclassed in the example project.</p>
<p>I&#8217;ve created a page dedicated to <a href="http://katidev.com/blog/ktuikit/">KTUIKit</a>.  It contains information about how to get it from Google Code and about using the framework in an Xcode project.  </p>
<p>If you have comments or feedback or if you&#8217;re interested in contributing to its development please feel free to email me. Here&#8217;s to a quick move to 1.0!</p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/11/12/ktuikit-090/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple NSViewController Sample Projects</title>
		<link>http://katidev.com/blog/2008/07/24/simple-nsviewcontroller-sample-projects/</link>
		<comments>http://katidev.com/blog/2008/07/24/simple-nsviewcontroller-sample-projects/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 11:52:25 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Sample Code]]></category>

		<category><![CDATA[NSViewController]]></category>

		<category><![CDATA[SampleCode]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=152</guid>
		<description><![CDATA[Hello!! 
Thanks for all of the feedback on the XS-Controllers design that Jonathan and I posted.  We&#8217;re going to be making some changes to the design based on feedback, bug reports and the experience we&#8217;ve had using it ourselves over the past few months. 
First, I want to take a few steps back and [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!! </p>
<p>Thanks for all of the feedback on the <a href="http://katidev.com/blog/2008/04/17/nsviewcontroller-the-new-c-in-mvc-pt-2-of-3/">XS-Controllers</a> design that Jonathan and I posted.  We&#8217;re going to be making some changes to the design based on feedback, bug reports and the experience we&#8217;ve had using it ourselves over the past few months. </p>
<p>First, I want to take a few steps back and offer a couple of example projects that use <a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController</a> – straight out of the box - in a non-document based application.  I hope these will be more useful for people who are just starting out with view controllers.  The projects do the following:</p>
<li>Create a view controller with a nib file</li>
<li>Add several view controllers&#8217; views to the window&#8217;s view hierarchy</li>
<li>Switching between two view controllers and their views</li>
<li>Patch a single view controller into the Responder Chain</li>
<p>There&#8217;s also a good <a href="http://developer.apple.com/samplecode/ViewController/listing11.html">sample project</a> available on Apple&#8217;s site.  I recommend checking it out. </p>
<h3> Simple View Controller Xcode Projects</h3>
<h4>Simple View Controller - Adding Views to the View Hierarchy</h4>
<p><a href="http://katidev.com/blog/wp-content/uploads/2008/07/simpleviewcontrollerpart1.zip" title="SimpleViewControllerPart1.zip"><img src="http://katidev.com/blog/wp-content/uploads/2008/07/xcodeprojecticon.png" alt="XcodeProjectIcon.png" border="0" width="25" height="21" align="left" />Download SimpleViewControllerPart1.zip</a></p>
<p>A window controller creates two view controllers and<br />
adds their views to the window&#8217;s view hierarchy.  The window controller keeps references to the view controllers as instance variables.  They are not added to the responder chain.</p>
<h4>Simple View Controller 2 - Switching View Controllers</h4>
<p><a href="http://katidev.com/blog/wp-content/uploads/2008/07/simpleviewcontrollerpart2.zip" title="SimpleViewControllerPart2.zip"><img src="http://katidev.com/blog/wp-content/uploads/2008/07/xcodeprojecticon.png" alt="XcodeProjectIcon.png" border="0" width="25" height="21" align="left" />Download SimpleViewControllerPart2.zip</a></p>
<p>This project extends the previous project so that the <strong>DetailViewController</strong> manages the switching between two other view controllers and adding their views to its &#8220;contentView&#8221;.  This gives you tab-like behavior with the addition of view controller switching instead of just view switching. </p>
<p>The <strong>DetailViewController</strong> is patched into the responder chain when it is created, after its view is added to the window, so that it can handle the View menu actions for switching the views.</p>
<h4>Note on the Responder Chain:</h4>
<p>If you take a look at the sample code, you&#8217;ll notice that I added the DetailViewController to the responder chain after the window controller.  This follows Jonathan&#8217;s and my design for the <strong>XSViewControllers</strong>.  Many people have asked why we didn&#8217;t add the <strong>XSViewControllers</strong> into the responder chain after their associated views instead.  There a couple of reasons for this:</p>
<li>A view controller can&#8217;t control when its view is added and removed from the view hierarchy, so in a design like ours, there is no reliable way to patch the chain in this way without subclassing and extending NSView to be aware of its view controllers.  This is a more intrusive design, in my opinion.
<li>There is a significant <em>behavior</em> difference between the two approaches.  Action messages take a <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/chapter_2_section_6.html#//apple_ref/doc/uid/10000060i-CH3-SW9">specific route</a> through the responder chain.  In order for a view controller to be able to validate a menu item, its view or one of its subviews will need to be the first responder.  <strong>This means that you have to subclass the view, override &#8216;acceptsFirstResponder&#8217; to return &#8220;YES&#8221; – AND that your user has to click in the view before going to the menu in order for the menu items to be usable.</strong>
<p>Placing the view controllers in the same part of the chain as the other controller classes ensures that the action message can travel to them, regardless of which view is the first responder.  The controllers can then decide which items to validate based on their own internal logic.
</li>
<p>To see the difference in behavior of the two approaches, change the sample code from the SimpleViewController2 project in the file <strong>MainWindowController.m</strong>, in the <strong>windowDidLoad:</strong> method:</p>
<pre>
	// patch the detail view into the responder chain
	NSResponder * aNextResponder = [self nextResponder];
	[self setNextResponder:mDetailViewController];
	[mDetailViewController setNextResponder:aNextResponder];
</pre>
<p>to</p>
<pre>
	// patch the detail view into the responder chain
	NSResponder * aNextResponder = [aDetailView nextResponder];
	[aDetailView setNextResponder:mDetailViewController];
	[mDetailViewController setNextResponder:aNextResponder];
</pre>
<p>After you make that change, build and run the project.  Click within the detail view area to make it the window&#8217;s First Responder.  Go to the &#8216;View&#8217; menu and the items will be validated.  Now click into the table view area and then return to the &#8216;View&#8217; menu.  The menu items won&#8217;t be validated.  You will have to click in the detail view area again to validate the menu items.  This isn&#8217;t the desired behavior for these menu items.  </p>
<p>Anyway&#8230;</p>
<h3>NSViewController and IB</h3>
<p>NSViewController is designed to be used with a nib file.  As you can with NSWindowController, you will initialize a view controller with the name of its associated nib file.  </p>
<pre>
mTableViewController = [[TableViewController alloc] initWithNibName:@"TableView" bundle:nil];
</pre>
<p>The view controller will automatically load the nib when it is asked to return its view for the first time.  In order for all of this to go smoothly, there are two things to be sure to do in your nib file:</p>
<h4>1.  Set the File&#8217;s Owner&#8217;s &#8220;Class&#8221; to be the NSViewController subclass that will be managing its view</h4>
<ol>
<li>Drag the view controller&#8217;s header file into the IB project or use the &#8220;Read Class Files&#8230;&#8221; command in the File menu and select the header file. </li>
<li>Select the &#8220;File&#8217;s Owner&#8221; object and go to &#8220;Identity&#8221; tab in the inspector palette. Start typing the class name of the view controller.  It should autocomplete for you.</li>
</ol>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/07/picture-161.png" alt="Picture 16.png" border="0" width="301" height="381" /></div>
<h4>2.  Connect the File&#8217;s Owner&#8217;s (your view controller) &#8220;view&#8221; outlet to the nib&#8217;s top level view.</h4>
<ol>
<li>Ctrl-drag from &#8220;File&#8217;s Owner&#8221; to the view.</li>
<li>Select the &#8220;view&#8221; outlet when the small context menu pops up.</li>
</ol>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/07/connectingoutlet.jpg" alt="ConnectingOutlet.jpg" border="0" width="507" height="402" /></div>
<p>That&#8217;s it!</p>
<h3>Resources</h3>
<p><a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController Class Reference</a></p>
<p><a href="http://developer.apple.com/samplecode/ViewController/listing11.html">Apple&#8217;s View Controller Sample Code</a> (shows example of switching view controllers)</p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/Reference/Reference.html#//apple_ref/occ/cl/NSResponder">NSResponder Class Reference</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/chapter_2_section_6.html#//apple_ref/doc/uid/10000060i-CH3-SW9">The Responder Chain for Action Messages</a> (from the docs on the Event Architecture)</p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/07/24/simple-nsviewcontroller-sample-projects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WWDC 2008!</title>
		<link>http://katidev.com/blog/2008/06/07/wwdc-2008/</link>
		<comments>http://katidev.com/blog/2008/06/07/wwdc-2008/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 21:35:15 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=137</guid>
		<description><![CDATA[I thought I could get the next post out before WWDC, but it seems doubtful at this point.  Sorry for the long pauses lately, I&#8217;ve had lots of work to do for my real job and it seems that it will be this way for the next month or so.
Anyway, if anyone wants to [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I could get the next post out before WWDC, but it seems doubtful at this point.  Sorry for the long pauses lately, I&#8217;ve had lots of work to do for my real job and it seems that it will be this way for the next month or so.</p>
<p>Anyway, if anyone wants to hang out in San Francisco next week, send me an email or a <a href="http://twitter.com/catshive">tweet</a> <img src='http://katidev.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
See you there!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/06/07/wwdc-2008/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NSViewController, the New C in MVC - Pt. 3 of 3</title>
		<link>http://katidev.com/blog/2008/05/26/nsviewcontroller-the-new-c-in-mvc-pt-3-of-3/</link>
		<comments>http://katidev.com/blog/2008/05/26/nsviewcontroller-the-new-c-in-mvc-pt-3-of-3/#comments</comments>
		<pubDate>Mon, 26 May 2008 19:31:20 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Layout]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[NSView]]></category>

		<category><![CDATA[NSViewController]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=127</guid>
		<description><![CDATA[The last two installments in this series focused on the challenge of integrating NSViewController into the controller layer of the current Cocoa MVC application architecture.  This is an important step to take, especially when developing a Cocoa application with a single window interface design. In a single window design, users will access most of [...]]]></description>
			<content:encoded><![CDATA[<p>The last two installments in this series focused on the challenge of integrating <a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController</a> into the controller layer of the current Cocoa MVC application architecture.  This is an important step to take, especially when developing a Cocoa application with a single window interface design. In a single window design, users will access most of the application&#8217;s features through one window rather than opening and closing several smaller windows as they are needed.  Since this one window will never close during a session, the multiple view controllers in the window will fill the role previously held by multiple window controllers in creating a dynamic Cocoa application.</p>
<p>The application&#8217;s view controllers will perform tasks like loading/unloading the content of nib files and their controllers as needed and validating/invalidating menu items as features are added or removed from the window.  Plugging NSViewController into the existing controller architecture is a simple way to provide it with the support it needs to fulfill these standard duties for your application.</p>
<p>However important these window controller-type tasks are, keep in mind that they are not the principle duty of a view controller.  Unlike <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html">NSWindowController</a>, NSViewController has a close relationship to the view layer of the Cocoa MVC design.  Each view controller manages a view in a view hierarchy.  A system of view controllers, like the system <a href="http://jonathandann.wordpress.com/">Jonathan Dann</a> and I described in the previous installment, manages the entire view hierarchy of a window. One of the most mission-critical jobs of a system of view controllers is to build and maintain the structure and layout of a complex view hierarchy in a dynamic environment.</p>
<p><img src="http://katidev.com/blog/wp-content/uploads/2008/04/lightroom.jpg" border="0" alt="lightroom.jpg" width="450" height="311" /></p>
<p style="font-size:12px; line-height:12pt;"><strong>Above:</strong> <a href="http://www.adobe.com/products/photoshoplightroom/">Adobe Photoshop Lightroom</a> is an example of a feature rich application with a single window interface design.</p>
<h3>Quick Quiz: what is a view hierarchy?</h3>
<p>Quick answer from the <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/WorkingWithAViewHierarchy/chapter_5_section_2.html#//apple_ref/doc/uid/TP40002978-CH4-SW13chapter_5_section_2.html#//apple_ref/doc/uid/TP40002978-CH4-SW13">docs</a> (emphasis is mine):</p>
<blockquote><p>In addition to being responsible for drawing and handling user events, a view instance can act as a container, enclosing other view instances. Those views are linked together creating a view hierarchy. Unlike a class hierarchy, which defines the lineage of a class, <strong>the view hierarchy defines the layout of views relative to other views.</strong></p></blockquote>
<h3>V + C, the dynamic layout duo</h3>
<p>There is a key difference between developing a Cocoa application that spreads its interface over several windows and one that uses a single window interface.  In a single window design, the <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/WorkingWithAViewHierarchy/chapter_5_section_2.html#//apple_ref/doc/uid/TP40002978-CH4-SW13chapter_5_section_2.html#//apple_ref/doc/uid/TP40002978-CH4-SW13">view hierarchy</a> of the application&#8217;s main window is much more complex and, most importantly, <em>dynamic</em> than Cocoa windows normally are.  In fact, the view hierarchy is a prominent character in this type of development. Managing its structure and layout throughout the application&#8217;s runtime is a significant design problem that should be addressed in a systematic way by the software&#8217;s MVC architecture – in both the controller and view layers.</p>
<p>NSViewController addresses this issue by providing support for building and managing the structure of a view hierarchy through its &#8220;view&#8221; instance variable.  Once you organize your view controllers into a coherent system, you have a convenient mechanism for accessing and adjusting the hierarchy from its significant branches.  But the problem is only half solved since changes in the view hierarchy are reflected by changes in the layout, and unfortunately, the issue of layout in a dynamic view environment remains to be addressed by Cocoa.</p>
<p>Building and maintaining a complex layout, like the one pictured above, requires cooperation from both the views and the controllers of a window.  The controllers are the dictators of the layout.  They tell the views <em>contained in their domain of the hierarchy</em> where to go and how to behave.  Unless the circumstances are very special, it&#8217;s up to the view hierarchy itself to do the calculations necessary to maintain the integrity of that layout as the forces within it change over time.  If either member of the layout duo fails to perform their duty, the interface will simply break.</p>
<h3>The problem with V</h3>
<p>In Cocoa, <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html">NSView</a> fails to perform its duty in this kind of system because it isn&#8217;t equipped with the right tools.  NSView has something called an <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/WorkingWithAViewHierarchy/chapter_5_section_6.html#//apple_ref/doc/uid/TP40002978-CH4-SW12">&#8220;autoresizing mask&#8221;</a>, which is meant to define the layout behavior of a view when its superview&#8217;s layout changes.  However, Autoresizing was never designed to function in a view hierarchy with a dynamic structure.  It is simply not the right tool for this job.  This is evidenced by one simple thing:  Autoresizing requires that a view is <em>already</em> laid out within its superview before you are supposed to set the desired resizing behavior.</p>
<p>This is well and good when you&#8217;re creating your entire layout in Interface Builder, where all the views are present and accounted for, but it&#8217;s simply not a practical limitation to make in a system of views and view controllers where elements of the layout will be added and removed during the application&#8217;s runtime.</p>
<p>It means that a view controller must have knowledge of it&#8217;s view&#8217;s superview and its frame before it can technically set a layout, but view controllers don&#8217;t necessarily have that information. For instance, when a view controller is initialized, it will create a view that will <em>eventually</em> be added to the view hierarchy.  At that moment, however, it doesn&#8217;t know anything about the view/controller hierarchy that it and its view are about to become a part of.  Technically, there&#8217;s no way for the controller to guarantee that the layout it dictates to its view (or more specifically, the view&#8217;s subviews) won&#8217;t be damaged by the layout of the view above it in the hierarchy.  Since NSViewController can&#8217;t always meet the requirements set forth by Autoresizing, the layout is exposed to the glitches and bugs that I&#8217;ve described in previous posts by default, and there&#8217;s nothing to be done about it except to take extra special care to explicitly size and position new views when adding them into the hierarchy and to set limits on how much the user is allowed to resize elements like split views and the window itself.  This is just extra grunt-work code that isn&#8217;t *really* necessary.  It&#8217;s a byproduct of the bugs in Autoresizing.</p>
<p>The bigger problem, one that does sometimes affect the design of the controllers, is that when a view controller makes a change to the existing view hierarchy, by either adding or removing views or manually adjusting the size or position of a view, it needs to take the view&#8217;s siblings into consideration.  The quote I pasted earlier, defining a view hierarchy, states that:</p>
<blockquote><p>the view hierarchy defines the layout of views relative to other views.</p></blockquote>
<p>What the docs really mean is that the layout of views is defined relative to their superviews.  The sibling views aren&#8217;t considered by the view hierarchy at all during autoresizing. So, any sibling that needs to move or resize as a result of the change needs to have its layout recalculated and its autoresizing mask re-set by the view controller that propagated the change – <em>even if the affected views aren&#8217;t in the controller&#8217;s domain of the view hierarchy</em>.  In this situation, the dynamic layout behavior of the view hierarchy becomes the responsibility of the view controller to maintain. This slippage of responsibility results in case-by-case workaround code that&#8217;s not only a pain in the ass to maintain, but that sometimes requires dependencies to views contained by other view controllers to be hard coded into the view controller.  All this does is make your view controllers less reusable by no fault of their own.  Again, none of this is necessary, it&#8217;s a byproduct of the limitations of Autoresizing.</p>
<h3>Absolute vs. Relative</h3>
<p>At the heart of the problem with Autoresizing, specifically in a dynamic system of views and view controllers, is the fact that there&#8217;s just nothing dynamic about it.  The mechanism is based on absolute positions and sizes, which makes it an inappropriate layout tool for this kind of interface development.  There are very few absolutes in a single window interface design.  Absolutes might include the height of a toolbar or the width of a control, but the state of the view hierarchy as a whole, at any given time during the app&#8217;s runtime, is variable.</p>
<p>A dynamic view hierarchy and its controller counterparts would be better served by a layout tool that can accommodate <strong>relative sizes and positions</strong>.  In a relative system, a view controller could just tell a newly created view to, for example, *fill* the width and height of its superview or *float* upwards in its superview – without having to specify any specific size or position (which might not be known anyway) – and the view hierarchy would work out the details once the view is in there.</p>
<p>Remember, view controllers have A LOT of responsibility in a Cocoa applicaiton.  They handle action events, load nib files, validate menu items, and sync up views to their data.  Why add managing the autoresizing behavior of the view hierarchy to their already long list of chores?</p>
<h3>Still more to come&#8230;</h3>
<p>So, yeah, I warned about the rant <img src='http://katidev.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Now I&#8217;ll try to offer a solution.</p>
<p>I&#8217;ve prepared an example project that illustrates how to use Jonathan&#8217;s and my controller subclasses, <strong>XSWindowController</strong> and <strong>XSViewController</strong> to build and manage a dynamic view hierarchy.  The project introduces an NSView subclass, <strong>KTView</strong>, into the mix.  Naturally, <strong>KTView</strong> uses an alternative to the Autoresizing mechanism that&#8217;s specifically designed to work within a changing view hierarchy.  It&#8217;s not a perfect solution (only Apple can do that), but it does get rid of the extra code from the view controllers that&#8217;s only there as a byproduct of Autoresizing.</p>
<p>The goal of the project is to bring together the concepts and opinions that have been covered in these three posts through examples of NSViewController in action.</p>
<p>I&#8217;ve decided that I don&#8217;t want to release <strong>KTView</strong> without an Interface Builder plugin, so I&#8217;ll publish the project with a tutorial as soon as that&#8217;s finished.</p>
<p>Until then, I found the original Smalltalk MVC Design paper, <a href="http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html">How to use Model-View-Controller</a>.  It&#8217;s interesting to read how Cocoa&#8217;s MVC design deviated from the original idea, especially when it comes to views and controllers.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/05/26/nsviewcontroller-the-new-c-in-mvc-pt-3-of-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Manual Input Sessions</title>
		<link>http://katidev.com/blog/2008/04/23/manual-input-sessions/</link>
		<comments>http://katidev.com/blog/2008/04/23/manual-input-sessions/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 10:30:49 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Art]]></category>

		<category><![CDATA[Input]]></category>

		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=113</guid>
		<description><![CDATA[In Computer Administrative Debris, I briefly discussed the idea of &#8220;directness&#8221; in interaction design.  I described a &#8220;direct&#8221; interaction model as one where the visual representation of the content and the interface to the content are the same.  A direct interaction model also implies some sort of physical interaction with content.  Today, [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://katidev.com/blog/2008/02/15/computer-administrative-debris/">Computer Administrative Debris</a>, I briefly discussed the idea of &#8220;directness&#8221; in interaction design.  I described a &#8220;direct&#8221; interaction model as one where the visual representation of the content and the interface to the content are the same.  A direct interaction model also implies some sort of physical interaction with content.  Today, we most frequently use the mouse as an extension of our bodies to &#8220;point&#8221; at objects on the screen and to &#8220;drag&#8221; or &#8220;drop&#8221; them.  With gesture and touch-based technologies entering the mainstream, these interactions will become more and more concerned with the movement and/or form of the user&#8217;s actual body. </p>
<p>A beautiful and extreme example of directness in an interface design can be found in the the software developed by <a href="http://www.flong.com/">Golan Levin</a> and <a href="http://www.thesystemis.com/">Zachary Lieberman</a> for their 2004 audio/visual performances, <a href="http://www.tmema.org/mis/">Manual Input Sessions</a>.</p>
<blockquote><p>
The Manual Input Sessions is a series of audiovisual vignettes which probe the expressive possibilities of hand gestures and finger movements.
</p></blockquote>
<p>Using a custom hardware/software setup, they developed interfaces for creating and composing audio in real-time that incorporate physical objects and the body into the interaction models.  Users of this software literally mold the audio with their hands over time.  </p>
<p>Also, when you watch the videos, notice how each interface has environmental characteristics that aid the user in creating and composing the audio.  This is a clever way to add extra meaning to the input data.  It also infuses the interfaces with a sense of play and exploration, so they become much more instrument-like and less tool-like.</p>
<p><strong>[these videos need sound]</strong></p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/IOwtu1B_DR4&#038;hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/IOwtu1B_DR4&#038;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/57vdcjLd6Yw&#038;hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/57vdcjLd6Yw&#038;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/iV-OoNTFS1E&#038;hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/iV-OoNTFS1E&#038;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/04/23/manual-input-sessions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NSViewController, the New C in MVC - Pt. 2 of 3</title>
		<link>http://katidev.com/blog/2008/04/17/nsviewcontroller-the-new-c-in-mvc-pt-2-of-3/</link>
		<comments>http://katidev.com/blog/2008/04/17/nsviewcontroller-the-new-c-in-mvc-pt-2-of-3/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 13:14:17 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[MVC]]></category>

		<category><![CDATA[NSViewController]]></category>

		<category><![CDATA[NSWindowController]]></category>

		<category><![CDATA[ResponderChain]]></category>

		<category><![CDATA[SampleCode]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=109</guid>
		<description><![CDATA[In the last post on NSViewController, I described the need for a view controller class that is part of a sound controller architecture, especially when developing an application with a single window interface. In this post, Jonathan Dann and I will share the design we came up with for integrating NSViewController into the existing Cocoa [...]]]></description>
			<content:encoded><![CDATA[<p>In the last post on <a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController</a>, I described the need for a view controller class that is part of a sound controller architecture, especially when developing an application with a single window interface. In this post, <a href="http://jonathandann.wordpress.com/">Jonathan Dann</a> and I will share the design we came up with for integrating NSViewController into the existing Cocoa MVC application architecture using <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html">NSWindowController</a> as the glue.  </p>
<p>Before, we do that&#8230;</p>
<h3>Meet Jonathan.</h3>
<p>I&#8217;m currently training with the National Health Service in the UK, working towards becoming a state-registered Medical Physicist. I was introduced to programming during my Bachelor&#8217;s degree where I did a short course in C. During my Master&#8217;s degree I learnt some FORTRAN and then had my first experience of object-oriented programming during that year.  Since then I&#8217;ve been learning as much as I could about Cocoa, design patterns, and the whole world of Mac programming. I&#8217;ve begun to write my first app, which will be available sometime around September, which really began life as a personal project when the tool I was using didn&#8217;t work right and didn&#8217;t fit properly within OS X.</p>
<p>As my code grew in size I soon realised that I needed a controller for some of my more complex view behaviour, NSSplitViews, NSTextViews, NSOutlineViews all need delegates to unlock their power and when all of this was in the same window controller I got the feeling it was doing work that it shouldn&#8217;t have to.  I started using NSViewController and came to the conclusion that it didn&#8217;t quite fit in my design, after considering how MVC should work I asked on cocoa-dev how other people use it. Sure enough, it sparked some conversation. I think that Apple has left the use of this class up to developers intentionally, maybe they will extend it in future releases, maybe having a structured controller system seems a little abstract for smaller programs, but I think it makes things easier to maintain in the long-run.</p>
<p>After using the class for a while I am of the mind that each view in an app could potentially have its own controller, although this would probably be overkill; the only structure that then makes sense is a tree, just like the view hierarchy.  I now use these classes extensively to inform the views, for example, how they should look: the view can then draw itself based on those options it gets from its overlord.</p>
<h3>The XS (extra special) Controllers</h3>
<p>Our solution includes to two classes:</p>
<ol>
<li><strong>XSWindowController</strong>, an NSWindowController subclass</li>
<li><strong>XSViewController</strong>, an NSViewController subclass</li>
</ol>
<p>You can find these classes in the example project (XCode 3.0).  Dowonload it <a href="http://katidev.com/blog/wp-content/uploads/2008/04/viewcontroller.zip">here</a>.</p>
<h3>The Goal of This Design</h3>
<p>The goal of our design is simple:  We want a way to manage a group of view controllers in a way that fits in nicely with the current Cocoa MVC architecture.  </p>
<p>When building a Cocoa app, the controller layer of the architecture can be described very loosely as: </p>
<ul>
<li>NSDocument contains a list of NSWindowControllers</li>
<li>Each window controller has an associated window</li>
</ul>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/04/cocoaarchitecture.jpg" alt="CocoaArchitecture.jpg" border="0" width="450" height="389" /></div>
<p>We want to extend this design so that:</p>
<ul>
<li>NSDocument contains a list of NSWindowControllers*</li>
<li>Each NSWindowController conains a list of NSViewControllers</li>
<li>Each NSViewController contains a list of subcontrollers</li>
<li>Each NSViewController has an associated view</li>
</ul>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/04/xsarch1.jpg" alt="XSArch.jpg" border="0" width="450" height="276" /></div>
<p>*Our changes happen beneath the document layer, so it is also a valid design for applications that aren&#8217;t document-based.</p>
<h3>XSViewController and XSWindowController</h3>
<p>In order to meet our goals, we enhanced Cocoa&#8217;s NSWindowController and NSViewController classes.</p>
<p>In <strong>XSViewController</strong>, we added a list of subcontrollers and the necessary methods to manage that list.  We also gave the view controllers a reference to the window controller.  </p>
<p>In <strong>XSWindowController</strong>, we added a list of view controllers.  The window controller is the &#8220;host&#8221; for the view controllers, so when the window controller is created and destroyed by the document, it does the same to the view controllers.  The window controller also does some extra work that is necessary for the view controllers to be integrated smoothly into the existing Cocoa controller architecture.  We&#8217;ll describe this work further down.</p>
<p>In this setup, you would use the following <strong>XSWindowController</strong> methods to add and remove view controllers,</p>
<pre>
- (void)addViewController:(XSViewController *)viewController;
- (void)removeViewController:(XSViewController *)viewController;
</pre>
<p>In <strong>XSViewController</strong>, you can nest controllers and manipulate the structure of the controller tree using several methods that will be familiar to those who have worked with mutable arrays,</p>
<pre>
- (void)addChild:(XSViewController *)child;
- (void)insertObject:(XSViewController *)child inChildrenAtIndex:(NSUInteger)index;
- (void)insertObjects:(NSArray *)children inChildrenAtIndexes:(NSIndexSet *)indexes;
- (void)insertObjects:(NSArray *)children inChildrenAtIndex:(NSUInteger)index;
- (void)removeChild:(XSViewController *)child;
- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index;
</pre>
<p>As long as you use these methods to add and remove view controllers from the application, you will get all of the benefits of the design. </p>
<p><strong>Quick design note: </strong></p>
<p>We want to note here that we considered a design where the window controller contained one view controller that would be the root of a single view controller tree.  We chose to keep a list of view controllers in the window controller because it feels redundant to have to make a second controller that represents the entire window.</p>
<p>In a perfect world, the view controllers and window controllers would actually be the same class, so that the window controller would be the root of a single tree of controllers.  This isn&#8217;t possible, but we decided that we would design with that structure in mind anyway.</p>
<h3>Working with Cocoa</h3>
<p>So, after we had this system set up and running, making sure that memory management was handled properly, we had to handle some Cocoa-specific behaviors so that the view controllers were well integrated into the Cocoa application architecture.  This is the &#8220;glue-code&#8221; of this design.  There are two Cocoa-related issues that we had to consider.</p>
<h4> Cocoa Consideration 1: Taking care of the Responder Chain</h4>
<p>NSViewController is a subclass of NSResponder, but it needs to be added to the responder chain to receive action events from things like buttons and menu items.  We decided that our design should patch the responder chain so that it runs through the view controllers like this:</p>
<p><img src="http://katidev.com/blog/wp-content/uploads/2008/04/responderchainsmall.jpg" alt="ResponderChainSmall.jpg" border="0" width="450" height="295" /></p>
<p>We looked at two approaches to solving this problem.  The first approach would be to handle the responder chain in the NSViewController class, so that when a view controller was added or removed from the tree, its super controller would make sure the responder chain was patched together correctly.</p>
<p>The other approach is to have the window controller do the responder chain patching whenever a view controller is added or removed. </p>
<p>Both of these approaches have their advantages and disadvantages.  </p>
<p>The first approach would keep things logically clean and less glue-like.  The view controllers wouldn&#8217;t have to communicate back to the window controller when they add or remove their subcontrollers.  If this were the perfect design world, where the window and view controllers were in the same tree, this would be the obvious way to maintain the responder chain throughout a single hierarchy of controllers.  </p>
<p>The second approach is just more simple in this particular setup.  Since this isn&#8217;t the perfect design world, the code that adds the view controllers to the responder chain would have to be repeated in both classes anyway.  Letting one class handle the responder chain keeps this code centralized.</p>
<p>We decided to use the second approach.  We don&#8217;t feel that there is a perfect solution to this problem and that either approach works fine.</p>
<p>The method that patches the responder chain is in <strong>XSWindowController</strong>:</p>
<pre>- (void)patchResponderChain;</pre>
<p>The source code will show how simple it is to keep the responder chain looking like it does in the diagram.</p>
<h4>Consideration 2: Bindings and Observations</h4>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html">Bindings</a> and <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html">Key-Value Observing</a> are powerful Cocoa mechanisms that help us to keep our controllers and our data models separate.  Most view controllers and window controllers will have bindings or KVO set up in some way.  </p>
<p>In NSViewController, there is the idea of a &#8220;representedObject&#8221;.  According to the documentation of NSViewController:</p>
<blockquote><p>Declaring a generic representedObject property, to make it easy to establish bindings in the nib to an object that isn&#8217;t yet known at nib-loading time or readily available to the code that&#8217;s doing the nib loading.</p></blockquote>
<p>This is a handy feature of NSViewController, especially if you are setting up all of your bindings in Interface Builder, but in a more complex setup, the single &#8220;representedObject&#8221; may not be the best way to expose a view controller to the data in an application.  </p>
<p>There are situations where you might want to set up several KVOs and bindings in code and then remove them when you don&#8217;t need them anymore.  If you forgo the &#8220;representedObject&#8221; as a means to set up KVO with your application&#8217;s data, you might come across this message in your logs when you close the document:</p>
<p><strong>An instance (so-and-so) of class (so-and-so) is being deallocated while key value observers are still registered with it.  Break on _NSKVODeallocateLog to start debugging.<br />
</strong></p>
<p>We decided to go ahead and handle the possibility of these situations by adding a method to <strong>XSViewController</strong> called,</p>
<pre>- (void)removeObservations;</pre>
<p>This gives the view controllers a chance to remove observations or bindings that they set up in code before the data is released. The window controller has to manage the timing of this.  In <strong>XSWindowController</strong>, we do it right before the window closes, in an implementation of the window&#8217;s delegate method,</p>
<pre>- (void)windowWillClose:(NSNotification *)notification;</pre>
<p>The window controller tells its view controllers to &#8220;removeObservations&#8221; here and they pass the message on to their subcontrollers.  The window controller and document can then release data as they normally would in their implementations of &#8220;dealloc&#8221;.</p>
<p><strong>Quick notes on subclassing:</strong></p>
<p>If an <strong>XSViewController</strong> subclass implements the &#8220;removeObservations&#8221; method, it is responsible for calling super&#8217;s implementation so that the message will continue to be propagated down its branch of the tree.  </p>
<p>If an <strong>XSWindowController</strong> subclass needs to implement &#8220;windowWillClose&#8221;, it should be sure to call super&#8217;s implementation so that the view controllers will get the message to remove their observations.  The timing of this message is important, so if you are releasing some data here, be sure to call super first.  </p>
<p>Using &#8220;windowWillClose&#8221; for a feature like this may not be the best solution, but as far as we can tell, it seems like the most convenient place to perform this task.</p>
<h3>That&#8217;s It.</h3>
<p>With these few enhancements, we now have two new abstract super-classes for our controllers, <strong>XSWindowController</strong> and <strong>XSViewController</strong>.  When we subclass them to build our UIs, we get the controller architecture that we illustrated at the beginning of the post and the following features built in to our view controller:</p>
<ul>
<li>Automatic memory management!</li>
<li>Automatic inclusion in the responder chain!!!</li>
<li>A designated method for removing observations or bindings!</li>
<li>A relationship with the window controller and document!</li>
</ul>
<p>This design will become more and more useful as your single window interface becomes more complex, especially as your feature set changes over the life-time of your development.  With this architecture in place, you have more flexibility to try things out and change your design without worrying about breaking the responder chain (which is not that easy to debug) or causing memory leaks by accident as you&#8217;re working rapidly to test UI designs.  As long as you keep to MVC design principles, it is possible to create self-contained view controllers that can be plugged in to, and unplugged from, your UI with very little hassle. </p>
<h3>Next Time&#8230;</h3>
<p>First, thanks so much to Jonathan for working on this post with me.  It was great to have the chance to brainstorm with another developer, especially one whose applications are completely different from the ones I work on every day.  Working with him on this design helped to get me out of my usual mind-set and to isolate the issues that are truly common to any Cocoa application rather than unique to my own projects.  This has been an educational and super-productive experience for me – Thanks, Jonathan!</p>
<p>AND a another big thanks to Jonathan for setting up the Xcode 3.0 <a href="http://katidev.com/blog/wp-content/uploads/2008/04/viewcontroller.zip">example project and the source code</a>!  </p>
<p>In the next and last post about NSViewController, I&#8217;m going to discuss its relationship to NSView and the view hierarchy in more detail.  One of the many important jobs of a view controller is to help to build and manage the view hierarchy during runtime.  This is especially important when coding a single window interface that needs to give users access to many different features that can&#8217;t all be displayed in the window at one time.</p>
<p>Anyone who is sick of me writing about autoresizing should just skip the next installment ; ) ( or in Japanese, ^_- )</p>
<h3>Resources</h3>
<p>The <a href="http://katidev.com/blog/wp-content/uploads/2008/04/viewcontroller.zip">example project</a> contains <strong>XSWindowController</strong> and <strong>XSViewController</strong>, which contain all the nitty-gritty implementation details.  There is also an example app that shows how you could subclass these classes to build a UI based on the XS controllers. </p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/chapter_2_section_6.html">Cocoa Event-Handling Guide: The Responder Chain</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Documents.html">Introduction to Document-Based Applications Overview</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController Class Reference</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html">NSWindowController Class Reference</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html">Introduction to Key-Value Observing Programming Guide</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html">Introduction to Cocoa Bindings Programming Topics</a></p>
<h3>UPDATE 04/23/08</h3>
<p>We updated the example project today.  The biggest change we made is in XSViewController.  We were previously setting the &#8220;representedObject&#8221; of child controllers to be that of its parent.  In the new version we don&#8217;t deal with &#8220;representedObject&#8221; in any way.  You can just use NSViewControllers methods to set them case-by-case.  </p>
<p><a href="http://katidev.com/blog/wp-content/uploads/2008/04/viewcontroller.zip">XCode Project</a></p>
<p><a href="http://katidev.com/blog/wp-content/uploads/2008/04/viewcontrollersource.zip" title="ViewControllerSource.zip">Just the Source Code</a></p>
<p><a href="http://katidev.com/blog/wp-content/uploads/2008/04/xscontrollers.zip" title="XSControllers.zip">Just XSViewController and XSWindowController</a></p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/04/17/nsviewcontroller-the-new-c-in-mvc-pt-2-of-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NSViewController, the New C in MVC - Pt. 1 of 3</title>
		<link>http://katidev.com/blog/2008/04/09/nsviewcontroller-the-new-c-in-mvc-pt-1-of-3/</link>
		<comments>http://katidev.com/blog/2008/04/09/nsviewcontroller-the-new-c-in-mvc-pt-1-of-3/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 10:11:05 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[NSViewController]]></category>

		<category><![CDATA[NSWindowController]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=99</guid>
		<description><![CDATA[
Applications like iTunes and iPhoto have established a single window interface as the de-facto standard for modern Mac UI design.  This design is great for end users, who no longer have to switch between several windows to be productive with their software.  For developers, on the other hand, this design poses several challenges [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/04/iphoto.jpg" alt="iPhoto.jpg" border="0" width="450" height="293" /></div>
<p>Applications like iTunes and iPhoto have established a single window interface as the de-facto standard for modern Mac UI design.  This design is great for end users, who no longer have to switch between several windows to be productive with their software.  For developers, on the other hand, this design poses several challenges in terms of interaction design and software architecture, especially in the view and controller layers of the MVC architecture prescribed by Cocoa.  This post is the first of three that will address this architectural design problem and, more specifically, examine the role of Cocoa&#8217;s new <a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController</a>  class in this design.</p>
<p>There are at least two major architectural issues that have to be addressed by the interface developer when coding this kind of interface. First, a single window interface requires a software architecture that can effectively handle dynamic changes in the view hierarchy during runtime.  I&#8217;ll address this issue in more detail in the third post on this topic.  </p>
<p>The second issue that needs to be addressed is that in a single window interface design, a great deal of burden naturally falls on <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.htmlReference.html">NSWindowController</a>.  In this type of setup, the application&#8217;s main window controller is responsible for handling a majority of the user interface.  In other words, the interface code for an entire application, apart from a few dialog windows here and there, is expected to go into one single class.  This code quickly becomes unmanageable and unmaintainable as the feature set changes and grows.  It is natural to start to break this code up into logical groups of subcontrollers and to develop a system to manage and maintain these groups.</p>
<p>To accomplish this, many of us have already come up with our own &#8220;view controller&#8221; systems to extend our controller architecture.  Apple has also started to address this issue by adding NSViewController to the Cocoa SDK in Leopard.  </p>
<p>A standard view controller class is a great idea and welcome addition to Cocoa.  One particular feature, the built-in memory management of objects in nib files, makes NSViewController a very attractive alternative to using a custom view controller.  However, this class seems to have been left out of the controller layer of Cocoa&#8217;s MVC application architecture. Apart from being a subclass of NSResponder, there is no indication from the documentation or the class&#8217;s design that it is intended to be a part of the current controller architecture, but at the same time, it cannot be functional on its own.  So where does NSViewController fit into a Cocoa app and how can developers use this class effectively to build a solid controller architecture in their applications?</p>
<h3>NSViewController and the Cocoa MVC Architecture</h3>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/03/apparchitecture.jpg" alt="AppArchitecture.jpg" border="0" width="450" height="397" /></div>
<p>For larger projects, specifically projects with single window interfaces, the view controllers form a significant portion of the software architecture and it would make sense for there to be a standard way to approach view controllers as a general design problem. Unfortunately, the Cocoa documentation doesn&#8217;t give developers any hint as to what that approach should be.  There are some clues in NSViewController&#8217;s API about how you could patch a single view controller into a specific area of your current design, but nothing that suggests a holistic design strategy. </p>
<p>The conceptual documentation of Cocoa&#8217;s <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Concepts/OverviewDocArchitecture.html#//apple_ref/doc/uid/20000023">&#8220;Document-Based Application Architecture&#8221;</a> hasn&#8217;t been updated yet to explain how the Cocoa engineers intend for us to incorporate NSViewController the current application architecture.  For example, the section that describes the &#8220;Key Objects&#8221; in the architecture makes no mention of NSViewController, and because of that, the paragraphs on &#8220;Typical Usage Patterns&#8221; still suggest that:</p>
<blockquote><p>If your document has only one window, but it is complex enough that you’d like to split up some of the logic in the controller layer, you can subclass NSWindowController as well as NSDocument. In this case, any outlets and actions and any other behavior that is specific to the management of the user interface goes into the NSWindowController subclass.</p></blockquote>
<p>Clearly a single NSWindowController subclass isn&#8217;t going to manage the whole user interface for an application like iPhoto.  This would be a perfect place to discuss the role of NSViewController.</p>
<p>I&#8217;ve given a lot of thought to the possibility that maybe it is better for Apple to leave this particular design decision to the developers.  As I mentioned, the view controllers in an application can grow into a significant portion of the architecture and it is annoying when Cocoa&#8217;s designs clash with your own.  However, if this is the case, what is the point of adding a view controller to Cocoa?  Those of us that have our own view controller system design already have our own view controller class that works in that design.  What is the incentive to use NSViewController instead of our own class if it doesn&#8217;t present a solution to the larger problem?</p>
<p>I&#8217;ve found from my own experience and from talking to other developers, that the design of a view controller system is the kind of design that tends to solve itself naturally within the current Cocoa MVC architecture.  There isn&#8217;t much room for imagination when it comes to its most basic structure.  If you ask developers how they organize their controllers, you&#8217;ll almost always get some variation of the same basic design:  view controllers own and manage a list of subcontrollers and the window controller owns and manages the view controllers.  It isn&#8217;t much different from the window and the view hierarchy.  The window has a content view and the content view has a list of subviews which contain a lists of subviews, etc.  </p>
<p>In fact, this particular relationship – the window and its views to the window controller and its view controllers – is very tight.  The view controllers and the window controller build and manage the view hierarchy.  The window controller has to add the view controllers&#8217; views to the window&#8217;s content view.  On top of that, the window controller needs to provide a way for the view controllers to enter the responder chain and, if there is a document, it should also give them access to that.  It seems logical that the relationship between NSWindowController and NSViewController should exist by default. The view controllers are, after all, an extension of the window controller. </p>
<p>When programming a large, single window interface, the first enhancements a developer is likely to make to NSViewController, before they can effectively use it in their application, is to add a list of subcontrollers and implement the methods to manage the list.  The next thing would be to establish some kind of  relationship between this structure of view controllers and NSWindowController.  These enhancements are enough to make NSViewController a key player in the current Cocoa controller archtitecture. </p>
<h3>Taking the Plunge</h3>
<p>The modifications to NSViewController that I mentioned above are simple enough for developers to make on their own.  But there are certain caveats that come up in the implementation details that are directly related to Cocoa.  These &#8220;gotchas&#8221; are not obvious until you start to test the design, but they also have to be dealt with before NSViewController can work effectively within the current controller architecture. </p>
<p>This is how I met <a href="http://jonathandann.wordpress.com/">Jonathan Dann</a> on the Cocoa-dev list.  Jonathan&#8217;s post was titled, <a href="http://www.cocoabuilder.com/archive/message/cocoa/2008/3/19/201743">&#8220;Correct use of NSViewController&#8221;</a>.  The title caught my attention because I had just finished my view controller design the week before.  I was not too surprised to see that his question had to do with implementing the exact design I&#8217;ve described in this post.  A few others chimed in with their solutions and it was very clear to me that this design is very obvious and that the issues in it were not unique to my implementation.  </p>
<p>Jonathan and I continued our discussion off-list and decided that we would write about the experience we had with NSViewController.  In the next post, he and I will describe the issues we came across when we tried to incorporate NSViewController into the Cocoa architecture and also provide our subclasses of NSViewController and NSWindowController as an example of how it might be accomplished.  </p>
<h4>To be continued&#8230;</h4>
<h3>Resources</h3>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Documents.html">Introduction to Document-Based Applications Overview</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html">NSViewController Class Reference</a></p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html">NSWindowController Class Reference</a></p>
<p>NSViewController documentation bug report - rdar://problem/5794739</p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/04/09/nsviewcontroller-the-new-c-in-mvc-pt-1-of-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sparkle And Spin</title>
		<link>http://katidev.com/blog/2008/03/25/sparkle-and-spin/</link>
		<comments>http://katidev.com/blog/2008/03/25/sparkle-and-spin/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 13:01:13 +0000</pubDate>
		<dc:creator>Cathy</dc:creator>
		
		<category><![CDATA[Graphic Design]]></category>

		<category><![CDATA[HIstory]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[PaulRand]]></category>

		<guid isPermaLink="false">http://katidev.com/blog/?p=94</guid>
		<description><![CDATA[
I found this 1993 video of Steve Jobs being interviewed about Paul Rand over on Paul Robinson&#8217;s site. It means so much to me when I see/read/hear someone that I admire admiring someone else that I admire.

Towards the end of the interview, Jobs is asked what his favorite Paul Rand work is.  His answer [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/03/paul-rand.jpg" border="0" alt="paul_rand.jpg" width="299" height="400" /></div>
<p>I found this 1993 video of Steve Jobs being interviewed about <a href="http://en.wikipedia.org/wiki/Paul_Rand">Paul Rand</a> over on <a href="http://kupuk.com/2008/03/18/jobs-on-paul-rand/">Paul Robinson</a>&#8217;s site. It means so much to me when I see/read/hear someone that I admire admiring someone else that I admire.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://www.youtube.com/v/xb8idEf-Iak&amp;hl=en" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://www.youtube.com/v/xb8idEf-Iak&amp;hl=en" wmode="transparent"></embed></object></p>
<p>Towards the end of the interview, Jobs is asked what his favorite Paul Rand work is.  His answer is also my favorite – an offshoot of his famous IBM logo.  It combines the wit and playfulness of his children&#8217;s illustrations with the discipline and craftsmanship of his corporate logos.  Rand&#8217;s personality shines in this image:</p>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/03/eye-bee-m.jpg" border="0" alt="eye-bee-m.jpg" width="435" height="163" /></div>
<p>Here are some of the children&#8217;s illustrations that I lifted from this <a href="p://www.logoblog.org/wordpress/tribute-to-a-legend-paul-rand/">post</a>.  &#8220;Sparkle and Spin&#8221; is the title of one of the children&#8217;s books he created with his wife, Ann.</p>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/03/paul-rand-design-work-2.jpg" border="0" alt="paul-rand-design-work-2.jpg" width="440" height="625" /></div>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/03/paul-rand-design-work-1.jpg" border="0" alt="paul-rand-design-work-1.jpg" width="440" height="435" /></div>
<p>And some of the corporate logos we all know too well&#8230;</p>
<div style="text-align:center;"><img src="http://katidev.com/blog/wp-content/uploads/2008/03/paulrandlogos.jpg" border="0" alt="PaulRandLogos.jpg" width="450" height="953" /></div>
<p>There&#8217;s an <a href="http://www.designobserver.com/archives/030468.html">article</a> on Design Observer with a funny story about how the Enron logo got its green after Paul Rand&#8217;s death in 1997.  The middle prong of the E was originally yellow.  The article describes all the fanfare and celebration that surrounded the unveiling of Enron&#8217;s new corporate identity but&#8230;</p>
<blockquote><p>Within hours, the world would laugh it off the stage. Houston faxed the logo to Enron&#8217;s offices in Europe. But in transmission the middle, yellow prong disappeared, leaving the new design meant to celebrate Enron&#8217;s triumphant ascension looking more like an electric plug. Worse, to the Italians it resembled an obscene hand gesture, one that meant about the same thing as shooting a middle finger at an American. The European executives roared with laughter: now they had a new way to win Italian customers.</p>
<p>Back in Houston, dismay grew: the yellow prong also vanished when run through the copying machine. Somehow, Enron had spent millions of dollars on a new business logo without bothering to check if it worked in business. Soon the hallway signs went down, the new cards and letterheads were shredded. With no fanfare, another logo was introduced, replacing the yellow prong with a green one.</p>
<p>The symbol meant to carry Enron into the next millennium hadn&#8217;t lasted a week.</p></blockquote>
<p>I would love to hear Rand&#8217;s comments on this teeny graphic design mishap.</p>
<p>One last treat.  The design company, <a href="http://imaginaryforces.com/company">Imaginary Forces</a>, did a great job animating Paul Rand&#8217;s work.  The animations are inter-cut with clips of Paul Rand speaking about design.  They&#8217;ve really captured his spirit with these animations.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://www.youtube.com/v/uK-lr_QeI_g&amp;hl=en" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://www.youtube.com/v/uK-lr_QeI_g&amp;hl=en" wmode="transparent"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://katidev.com/blog/2008/03/25/sparkle-and-spin/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.636 seconds -->
<!-- Cached page served by WP-Cache -->
