<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Corbin&#039;s Treehouse &#187; Cocoa</title>
	<atom:link href="http://www.corbinstreehouse.com/blog/category/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.corbinstreehouse.com/blog</link>
	<description>Corbin Dunn and Louise Lovelle</description>
	<lastBuildDate>Wed, 01 Sep 2010 03:27:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Why the API? NSTableView -preparedCellAtColumn:row:</title>
		<link>http://www.corbinstreehouse.com/blog/2008/09/why-the-api-nstableview-preparedcellatcolumnrow/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/09/why-the-api-nstableview-preparedcellatcolumnrow/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 05:21:11 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/?p=431</guid>
		<description><![CDATA[I think I&#8217;ll do a few articles on why certain API was introduced in Leopard.
I&#8217;ll start with one of the new methods in NSTableView:

/* Returns the fully prepared cell that the view will normally use for
 drawing or any processing. The value for the cell will be correctly set,
 and the delegate method 'willDisplayCell:' will [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I think I&#8217;ll do a few articles on why certain API was introduced in Leopard.</p>
<p>I&#8217;ll start with one of the new methods in NSTableView:</p>
<pre class="code">
/* Returns the fully prepared cell that the view will normally use for
 drawing or any processing. The value for the cell will be correctly set,
 and the delegate method 'willDisplayCell:' will have be called. You can
 override this method to do any additional setting up of the cell that is
 required, or call it to retrieve a cell that will have its contents properly
 set for the particular column and row.
*/
- (NSCell *)preparedCellAtColumn:(NSInteger)column row:(NSInteger)row;
</pre>
<p>What is this method and what is it useful for? There are many reasons why it is useful, and they all are based on this fact: *all* of NSTableView&#8217;s operations that involve a cell at a particular row/column will be filtered through this method. Previously, NSTableView would have various internal methods and ways of obtaining the cell and there was no single spot where everything filtered through. Now there is.</p>
<p>This means:</p>
<p>1. You can acquire a &#8220;fully prepared&#8221; cell that is ready to draw &#8212; either in the NSTableView itself, or somewhere else. Somewhere else? Yes &#8212; an example where AppKit does this is for expansion tool tips, which draw in a separate tool tip window and in a view that is not actually an NSTableView. You might also want to access the &#8220;fully prepared&#8221; cell to generate a drag image when you override:</p>
<pre class="code">
- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows
	tableColumns:(NSArray *)tableColumns
	event:(NSEvent*)dragEvent
	offset:(NSPointPointer)dragImageOffset;
</pre>
<p>2. You can override the method to modify the cell. Think about this in a simple way, and it means you could easily bold odd rows without having to use -willDisplayCell:. Depending on how your code is setup, it might make more sense to do this work in the view, as opposed to the controller (via the delegate).</p>
<p>3. You can return an entirely different cell. Let&#8217;s say you want to have one cell that doesn&#8217;t change for one particular row; well, you can just always return that same cell, and it will always be used. You might want to do this if that particular cell has some sort of important state (such as an animation), which you don&#8217;t want to have to keep resetting or managing. Another example is for showing highlighting when you mouse over the cell. </p>
<p>Take this example from WWDC that I wrote a few years ago: <a href="http://developer.apple.com/samplecode/PhotoSearch/index.html">PhotoSearch</a>. Look at <a href="http://developer.apple.com/samplecode/PhotoSearch/listing21.html">TrackableOutlineView.m</a>, and you&#8217;ll see that the cell which is being tracked (ie: mouse is over it), is always returned from preparedCellAtColumn:row:. This was important from an abstraction perspective; the cell will get a single -mouseEntered: from the tracking area, and the same cell will eventually get a -mouseExited: &#8212; this allows the cell to set and maintain its own state, without forcing the delegate or NSTableView to save off the state and always reset it at draw time. </p>
<p>Why does this demo copy the cell, and not just use the single cell that is shared from the [tableColumn dataCell]? I mean, if the cell gets a mouseEntered:, and the tableView redraws *just* that cell, then things will work out fine, right? Yes &#8212; but if something else triggers any other row to redraw, then your tracked cell will be used, and it currently has the wrong state in it. That would be bad, and it would draw the wrong thing.</p>
<p>4. Another reason this method is useful is for type selection. When you type select, and NSTableView is attempting to find a row, it can acquire a fully prepared cell (including setting the stringValue, calling -willDisplayCell on the delegate, and setting up bindings). The stringValue of the cell can then be compared for type-selection to find a match. But, you wonder, isn&#8217;t that doing too much work for just matching on the string? Yes &#8212; for any decent sized table, you should implement this delegate method to directly return information from your model:</p>
<pre>
- (NSString *)tableView:(NSTableView *)tableView
	typeSelectStringForTableColumn:(NSTableColumn *)tableColumn
	row:(NSInteger)row;
</pre>
<p>5. Finally, another reason for the API; there is no easy way to know what the value of a cell will be if you are using bindings. Now, you can find out by using this method, since it will fill the cell&#8217;s content with bound values (if there are any).</p>
<p>Anyways, my first entry of &#8220;Why the API&#8221;. More to follow&#8230;hopefully.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/09/why-the-api-nstableview-preparedcellatcolumnrow/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cocoa programmers: avoid writing to the user defaults when you don&#8217;t need to</title>
		<link>http://www.corbinstreehouse.com/blog/2008/08/cocoa-programmers-avoid-writing-to-the-user-defaults-when-you-dont-need-to/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/08/cocoa-programmers-avoid-writing-to-the-user-defaults-when-you-dont-need-to/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 17:49:43 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/index.php/2008/08/cocoa-programmers-avoid-writing-to-the-user-defaults-when-you-dont-need-to/</guid>
		<description><![CDATA[
[Edit: ecto ate this post, so I'm typing it in again!]
I discovered that a lot of applications will unnecessarily write to NSUserDefaults. This causes your app to hit the disk when it shouldn&#8217;t, and is a slight performance penalty. AppKit is also susceptible to this problem; if you hit cmd-O to bring up the open [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>[Edit: ecto ate this post, so I'm typing it in again!]</p>
<p>I discovered that a lot of applications will unnecessarily write to NSUserDefaults. This causes your app to hit the disk when it shouldn&#8217;t, and is a slight performance penalty. AppKit is also susceptible to this problem; if you hit cmd-O to bring up the open panel in any application, you will see it writing things to the user defaults, when it probably doesn&#8217;t need to do so. I&#8217;m working on fixing that, and you should to!</p>
<p>So, how do you do it? It is easy &#8212; just add a breakpoint on -[NSUserDefaults(NSUserDefaults) setObject:forKey:]. You can do this with gdb:</p>
<p><span style="font-family: Courier;">b -[NSUserDefaults(NSUserDefaults) setObject:forKey:]</span></p>
<p>Or you can use the breakpoints window in Xcode (my preferred way):</p>
<p><a href="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/picture4-breaking-on-user-defaults.jpg"><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/picture4-breaking-on-user-defaults-tm.jpg" width="450" height="260" alt="Picture4 - breaking on user defaults.png" /></a></p>
<p>Then, reproduce whatever action might cause it to happen (ie: starting your application, or in my test case, cmd-o to bring up the open panel). Look at the backtrace in Xcode and figure out why you are doing too much work:</p>
<p>
<a href="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/picture5-the-callstack-for-a-user-default.jpg"><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/picture5-the-callstack-for-a-user-default-tm.jpg" width="450" height="324" alt="Picture5 - the callstack for a user default.png" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/08/cocoa-programmers-avoid-writing-to-the-user-defaults-when-you-dont-need-to/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Getting rid of the undo warning in Xcode after saving</title>
		<link>http://www.corbinstreehouse.com/blog/2008/08/getting-rid-of-the-undo-warning-in-xcode-after-saving/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/08/getting-rid-of-the-undo-warning-in-xcode-after-saving/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 18:02:07 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/index.php/2008/08/getting-rid-of-the-undo-warning-in-xcode-after-saving/</guid>
		<description><![CDATA[
One of the most annoying dialogs in Xcode is the undo warning dialog you get when attempting to undo after a save. I do this all the time, and I hate the warning. Luckily, there is a user default to turn it off:
defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO
]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>One of the most annoying dialogs in Xcode is the undo warning dialog you get when attempting to undo after a save. I do this all the time, and I hate the warning. Luckily, there is a user default to turn it off:</p>
<p><span style="font-family: -webkit-monospace;">defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/08/getting-rid-of-the-undo-warning-in-xcode-after-saving/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wake up and smell the cocoa</title>
		<link>http://www.corbinstreehouse.com/blog/2008/08/wake-up-and-smell-the-cocoa/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/08/wake-up-and-smell-the-cocoa/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 23:40:35 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/index.php/2008/08/wake-up-and-smell-the-cocoa/</guid>
		<description><![CDATA[

]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p><a href="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/p-640-480-318d4650-32a8-4425-a7a3-32615541c657.jpeg"><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/p-640-480-318d4650-32a8-4425-a7a3-32615541c657.jpeg" alt="" width="225" height="300" class="alignnone size-full wp-image-364" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/08/wake-up-and-smell-the-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your most important breakpoint in Cocoa</title>
		<link>http://www.corbinstreehouse.com/blog/2008/08/your-most-important-breakpoint-in-cocoa/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/08/your-most-important-breakpoint-in-cocoa/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 00:29:44 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/index.php/2008/08/your-most-important-breakpoint-in-cocoa/</guid>
		<description><![CDATA[
&#8230;..drumroll please&#8230;and it is&#8230;is: objc_exception_throw. You should always have this breakpoint setup in any Cocoa or Cocoa Touch app that you are building.
How do you do it? In Xcode, Run -&#62; Show -&#62; Breakpoints and double click on a new breakpoint. Type it in, ie:

Exceptions in cocoa are, well, exceptional. If your app is throwing [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>&#8230;..drumroll please&#8230;and it is&#8230;is: objc_exception_throw. You should always have this breakpoint setup in any Cocoa or Cocoa Touch app that you are building.</p>
<p>How do you do it? In Xcode, Run -&gt; Show -&gt; Breakpoints and double click on a new breakpoint. Type it in, ie:</p>
<p><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/picture-3-objc-exception-throw.jpg" width="503" height="121" alt="Picture 3 objc exception throw.png" /></p>
<p>Exceptions in cocoa are, well, exceptional. If your app is throwing them, then you should fix them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/08/your-most-important-breakpoint-in-cocoa/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Xcode code completion and your code</title>
		<link>http://www.corbinstreehouse.com/blog/2008/08/xcode-code-completion-and-your-code/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/08/xcode-code-completion-and-your-code/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 16:33:24 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/index.php/2008/08/xcode-code-completion-and-your-code/</guid>
		<description><![CDATA[
How can you become a faster Cocoa programmer? One way is to adequately name your variables, enums and classes.
Let&#8217;s start with enums and take an example from something new to NSTableView in Leopard. This is copied from NSTableView.h with the comments stripped out for clarity.
enum {
NSTableViewSelectionHighlightStyleRegular = 0,
NSTableViewSelectionHighlightStyleSourceList = 1,
};
typedef NSInteger NSTableViewSelectionHighlightStyle;
- (NSTableViewSelectionHighlightStyle)selectionHighlightStyle;
- (void)setSelectionHighlightStyle:(NSTableViewSelectionHighlightStyle)selectionHighlightStyle;

There are [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>How can you become a faster Cocoa programmer? One way is to adequately name your variables, enums and classes.</p>
<p>Let&#8217;s start with enums and take an example from something new to NSTableView in Leopard. This is copied from NSTableView.h with the comments stripped out for clarity.</p>
<p><span style="color: #AA0D91; font-family: Monaco; font-size: 10px;">enum <span style="color: #000000">{</span></span></p>
<p style="font: 10.0px Monaco; color: #007400"><span style="color: #2E0D6E;">NSTableViewSelectionHighlightStyleRegular <span style="color: #000000">=</span> <span style="color: #1c00cf">0</span><span style="color: #000000">,</span></span></p>
<p style="font: 10.0px Monaco; min-height: 14.0px"><span style="color: #2E0D6E;">NSTableViewSelectionHighlightStyleSourceList <span style="color: #000000">=</span> <span style="color: #1c00cf">1</span><span style="color: #000000">,</span></span></p>
<p style="font: 10.0px Monaco">};</p>
<p style="font: 10.0px Monaco"><span style="color: #aa0d91">typedef</span> NSInteger NSTableViewSelectionHighlightStyle;</p>
<p style="font: 10.0px Monaco; color: #007400"><span style="color: #5C2699;"><span style="color: #000000">- (</span>NSTableViewSelectionHighlightStyle<span style="color: #000000">)selectionHighlightStyle;</span></span></p>
<p style="font: 10.0px Monaco">- (<span style="color: #aa0d91">void</span>)setSelectionHighlightStyle:(<span style="color: #5c2699">NSTableViewSelectionHighlightStyle</span>)selectionHighlightStyle;</p>
<p>
There are several things to notice here, some of which are important to you. The most important thing (in my opinion) is the common prefix. Notice that the enum values fully contain the enum type name. Why? The answer is code completion, which you should be using. It is much easier to remember one key portion of the name than to remember all values. In this case, the key thing to remember is &#8220;selection&#8221;.<br />
As a programmer working with NSTableView you <strong>know</strong> you want to change the selection highlight style, but you don&#8217;t remember the option for the specific style you want. You <strong>know</strong> the Cocoa convention is setFoo, so you type:</p>
<pre class="code">
[tableView set
</pre>
<p>And hit escape (or whatever key combo invokes code completion for you. For me, I remapped the key to ctrl-space, since I was used to Delphi and Visual Studio. But, I also use escape).<br />
You see this result:</p>
<p><a href="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/tableviewset-codecomplete.jpg"><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/tableviewset-codecomplete-tm.jpg" width="500" height="209" alt="TableViewSet_CodeComplete.png" /></a></p>
<p>and start typing &#8220;sel&#8221; to see the result you want:</p>
<p><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/tableviewsetselresult.jpg" width="653" height="82" alt="TableViewSetSelResult.png" /><br />
Which inserts this template:</p>
<p><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/tableviewsettemplate.jpg" width="611" height="25" alt="TableViewSetTemplate.png" /><br />
Now, I&#8217;m surprised, but most people don&#8217;t realize that they can type ctrl-/ (or maybe alt-/ depending on your key bindings) to select the placeholder and type over it. Memorize that keystroke, and use it.<br />
Now, the common prefix name comes in <strong>really</strong> handy with code completion &#8212; just start typing in the type that the placeholder tells you and you&#8217;ll see what options you have:</p>
<p><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/08/tableviewsetoptions.jpg" width="587" height="110" alt="TableViewSetOptions.png" /><br />
In essence, you only have to remember &#8220;sel&#8221;, and from there you can derive exactly what option you want using code completion. Less memorization, and faster programming.<br />
Unfortunately, a lot of Cocoa came along before code completion, and doesn&#8217;t follow this convention. But if you look at a new UI framework (ala: UIKit for the iPhone), you&#8217;ll find this pattern throughout it. It makes programming very fast with fewer trips to the header to find out what you need.</p>
<p>The bottom line: use a common prefix, wherever you have a list of options. Also note that the NSTableViewSelectionHighlightStyle has the prefix NSTableView, since it <strong>only</strong> applies to NSTableView. But, the property name is &#8220;selectionHighlightStyle&#8221;, since it doesn&#8217;t make sense to replicate the type name there.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/08/xcode-code-completion-and-your-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WWDC 2008</title>
		<link>http://www.corbinstreehouse.com/blog/2008/06/wwdc-2008/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/06/wwdc-2008/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 15:52:16 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/index.php/2008/06/wwdc-2008/</guid>
		<description><![CDATA[
WWDC 2008! Howdy to my fellow Cocoa Developers. Take a look at the conference schedule: http://developer.apple.com/wwdc/schedules/ and be sure to come to my talk! Tuesday at 10:30 AM, iPhone for Mac Developers.
If you have *any* Cocoa questions, come to the Cocoa labs! I&#8217;ll be working the labs this week, so find me (or any of [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p><a href="http://developer.apple.com/wwdc/" title="WWDC 2008!">WWDC 2008!</a> Howdy to my fellow Cocoa Developers. Take a look at the conference schedule: <a href="http://developer.apple.com/wwdc/schedules/" title="http://developer.apple.com/wwdc/schedules/">http://developer.apple.com/wwdc/schedules/</a> and be sure to come to my talk! Tuesday at 10:30 AM, iPhone for Mac Developers.</p>
<p>If you have *any* Cocoa questions, come to the Cocoa labs! I&#8217;ll be working the labs this week, so find me (or any of the other great apple engineers) and ask questions!</p>
<p>Edit: if you go to: <a href="http://developer.apple.com/wwdc/students/" title="http://developer.apple.com/wwdc/students/">http://developer.apple.com/wwdc/students/</a> you can see a picture of me from last year &#8212; I have the Leopard print hair:</p>
<p><img src="http://www.corbinstreehouse.com/blog/wp-content/uploads/2008/06/picture-1.jpg" width="1092" height="350" alt="Picture 1.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/06/wwdc-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: willDisplayCell delegate method of NSTableView, [NSCell setTextColor], and &#8220;source lists&#8221;</title>
		<link>http://www.corbinstreehouse.com/blog/2008/01/cocoa-willdisplaycell-delegate-method-of-nstableview-nscell-settextcolor-and-source-lists/</link>
		<comments>http://www.corbinstreehouse.com/blog/2008/01/cocoa-willdisplaycell-delegate-method-of-nstableview-nscell-settextcolor-and-source-lists/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 21:09:17 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/?p=273</guid>
		<description><![CDATA[
Mac OS 10.5 added a &#8220;source list&#8221; highlighting style to NSTableView, with the API below for your reference:
enum {
NSTableViewSelectionHighlightStyleRegular = 0,
NSTableViewSelectionHighlightStyleSourceList = 1,
};
typedef NSInteger NSTableViewSelectionHighlightStyle;

- (NSTableViewSelectionHighlightStyle)selectionHighlightStyle;
- (void)setSelectionHighlightStyle:(NSTableViewSelectionHighlightStyle)selectionHighlightStyle;

Source lists should have bold text when the item is selected, and NSTableView attempts to auto-format the cell&#8217;s contents to automatically do this for you, as seen in this [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>Mac OS 10.5 added a &#8220;source list&#8221; highlighting style to NSTableView, with the API below for your reference:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91">enum <span style="color: #000000">{</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #2E0D6E;">NSTableViewSelectionHighlightStyleRegular</span> <span style="color: #000000">=</span> <span style="color: #1c00cf">0</span><span style="color: #000000">,</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span style="color: #2E0D6E;">NSTableViewSelectionHighlightStyleSourceList</span> <span style="color: #000000">=</span> <span style="color: #1c00cf">1</span><span style="color: #000000">,</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #5c2699"><span style="color: #aa0d91">typedef</span> NSInteger NSTableViewSelectionHighlightStyle<span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #000000">- (</span>NSTableViewSelectionHighlightStyle<span style="color: #000000">)selectionHighlightStyle;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">- (<span style="color: #aa0d91">void</span>)setSelectionHighlightStyle:(<span style="color: #5c2699">NSTableViewSelectionHighlightStyle</span>)selectionHighlightStyle;</p>
<p><span style="font-family: Monaco; font-size: 10px;"><br /></span></p>
<p>Source lists should have bold text when the item is selected, and NSTableView attempts to auto-format the cell&#8217;s contents to automatically do this for you, as seen in this screen shot for the selected item in the open panel source list:</p>
<p><img src="/blog/wp-content/uploads/open_panel_selected_item_source_list2.png" width="234" height="60" /></p>
<p>However, the code that does this formatting does so by converting the &#8217;stringValue&#8217; of the cell to an attributedStringValue that has the bold text. This is done *before* calling the delegate with &#8220;willDisplayCell&#8221;. The delegate gets the final say of how it looks in &#8220;willDisplayCell&#8221;, but this can cause unexpected results if you want to do something like this:</p>
<p><span style="font-family: Monaco; font-size: 10px;">- (</span><span style="color: #aa0d91">void</span>)tableView:(<span style="color: #5c2699">NSTableView</span> *)tableView willDisplayCell:(<span style="color: #aa0d91">id</span>)cell forTableColumn:(<span style="color: #5c2699">NSTableColumn</span> *)tableColumn row:(<span style="color: #5c2699">NSInteger</span>)row {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"><span style="color: #aa0d91">if</span>(row == <span style="color: #1c00cf">0</span>) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">[cell <span style="color: #2e0d6e">setTextColor</span>: [<span style="color: #5c2699">NSColor</span> <span style="color: #2e0d6e">redColor</span>]];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">} <span style="color: #aa0d91">else</span> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e"><span style="color: #000000">[cell</span> setTextColor<span style="color: #000000">: [</span><span style="color: #5c2699">NSColor</span> blackColor<span style="color: #000000">]];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">}</p>
<p>The problem with the above code is that it is *too late* for the coloring to be correctly applied to the cell if it is selected. The work around is easy; you need to color the cell text earlier, and a perfect place to do that is in the new 10.5 delegate method &#8220;dataCellForTableColumn:&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">- (<span style="color: #5c2699">NSCell</span> *)tableView:(<span style="color: #5c2699">NSTableView</span> *)tableView dataCellForTableColumn:(<span style="color: #5c2699">NSTableColumn</span> *)tableColumn row:(<span style="color: #5c2699">NSInteger</span>)row {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"><span style="color: #5c2699">NSTextFieldCell</span> *cell = [tableColumn <span style="color: #2e0d6e">dataCell</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"><span style="color: #aa0d91">if</span>(row == <span style="color: #1c00cf">0</span>) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">[cell <span style="color: #2e0d6e">setTextColor</span>: [<span style="color: #5c2699">NSColor</span> <span style="color: #2e0d6e">redColor</span>]];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">} <span style="color: #aa0d91">else</span> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e"><span style="color: #000000">[cell</span> setTextColor<span style="color: #000000">: [</span><span style="color: #5c2699">NSColor</span> blackColor<span style="color: #000000">]];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"><span style="color: #aa0d91">return</span> cell;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">}</p>
<p>Cool. Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2008/01/cocoa-willdisplaycell-delegate-method-of-nstableview-nscell-settextcolor-and-source-lists/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Overriding shortcut keys in the NSOpenPanel or NSSavePanel</title>
		<link>http://www.corbinstreehouse.com/blog/2007/12/overriding-shortcut-keys-in-the-nsopenpanel-or-nssavepanel/</link>
		<comments>http://www.corbinstreehouse.com/blog/2007/12/overriding-shortcut-keys-in-the-nsopenpanel-or-nssavepanel/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 17:16:38 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/?p=268</guid>
		<description><![CDATA[
It recently came up where someone needed to override some of the default shortcut keys in the NSOpenPanel or NSSavePanel. This is quite trivial to do. First off, the &#8220;easy way&#8221; would be to add a hidden NSPopUpButton in an accessory view that has the appropriate shortcuts. However, that won&#8217;t override the defaults (ie: cmd-r [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>It recently came up where someone needed to override some of the default shortcut keys in the NSOpenPanel or NSSavePanel. This is quite trivial to do. First off, the &#8220;easy way&#8221; would be to add a hidden NSPopUpButton in an accessory view that has the appropriate shortcuts. However, that won&#8217;t override the defaults (ie: cmd-r == reveal in finder, cmd-i == finder info window, cmd-a == select all, etc). To override these, you would subclass the appropriate panel:</p>
<p><span style="font-family: Monaco; font-size: 10px;"></span><span style="color: #aa0d91">@interface</span> MyOpenPanel : NSOpenPanel</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span style="color: #AA0D91;">@end</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91">@implementation <span style="color: #000000">MyOpenPanel</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">- (<span style="color: #aa0d91">BOOL</span>)performKeyEquivalent:(<span style="color: #5c2699">NSEvent</span> *)theEvent {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #2e0d6e">NSLog</span><span style="color: #000000">(</span><span style="color: #c41a16">@&#8221;&#8230;test&#8221;</span><span style="color: #000000">);</span> // an example of where you would do your key testing</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e"><span style="color: #aa0d91">return</span> <span style="color: #000000">[</span><span style="color: #aa0d91">super</span> performKeyEquivalent<span style="color: #000000">:theEvent];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91">@end</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: 10px Monaco;"><span style="font-family: Helvetica; font-size: 12px;">You would then use it via something like:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"><span style="color: #000000">[</span>MyOpenPanel <span style="color: #2e0d6e">openPanel</span><span style="color: #000000">]</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"><span style="color: #000000;"><br /></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"><span style="color: #000000;"></span><span style="font-family: Helvetica; font-size: 12px;">Easy to do&#8230;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2007/12/overriding-shortcut-keys-in-the-nsopenpanel-or-nssavepanel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leopard: PhotoSearch demo app now live</title>
		<link>http://www.corbinstreehouse.com/blog/2007/11/leopard-photosearch-demo-app-now-live/</link>
		<comments>http://www.corbinstreehouse.com/blog/2007/11/leopard-photosearch-demo-app-now-live/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 22:11:33 +0000</pubDate>
		<dc:creator>corbin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.corbinstreehouse.com/blog/?p=262</guid>
		<description><![CDATA[
PhotoSearch, a demo app I wrote for WWDC a few years ago, is now live:
http://developer.apple.com/samplecode/PhotoSearch/
It demonstrates some cool custom cell stuff that is only available on Leopard.
]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>PhotoSearch, a demo app I wrote for WWDC a few years ago, is now live:</p>
<p><a href="http://developer.apple.com/samplecode/PhotoSearch/" title="http://developer.apple.com/samplecode/PhotoSearch/">http://developer.apple.com/samplecode/PhotoSearch/</a></p>
<p>It demonstrates some cool custom cell stuff that is only available on Leopard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corbinstreehouse.com/blog/2007/11/leopard-photosearch-demo-app-now-live/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
