<?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>Kickass Labs &#187; objc</title>
	<atom:link href="http://www.kickasslabs.com/tag/objc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kickasslabs.com</link>
	<description>We &#9829; code.</description>
	<lastBuildDate>Wed, 28 Dec 2011 16:57:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quick Hits: UIActionSheet cancel button strange behaviour</title>
		<link>http://www.kickasslabs.com/2010/07/03/uiactionsheet-cancel-button-strange-behaviour/</link>
		<comments>http://www.kickasslabs.com/2010/07/03/uiactionsheet-cancel-button-strange-behaviour/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 02:41:39 +0000</pubDate>
		<dc:creator>abel</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Hits]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.kickasslabs.com/2010/07/03/uiactionsheet-cancel-button-strange-behaviour/</guid>
		<description><![CDATA[I just got bit by this and fixed it thanks to this StackOverflow post. http://stackoverflow.com/questions/1197746/uiactionsheet-cancel-button-strange-behaviour Long story short, if your launch an action sheet in a view that lives in a UITabBarController, the &#8220;hit&#8221; box for the cancel button gets &#8230; <a href="http://www.kickasslabs.com/2010/07/03/uiactionsheet-cancel-button-strange-behaviour/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just got bit by this and fixed it thanks to this StackOverflow post.</p>
<p><a href="http://stackoverflow.com/questions/1197746/uiactionsheet-cancel-button-strange-behaviour" target="_blank">http://stackoverflow.com/questions/1197746/uiactionsheet-cancel-button-strange-behaviour</a></p>
<p>Long story short, if your launch an action sheet in a view that lives in a UITabBarController, the &#8220;hit&#8221; box for the cancel button gets shifted in a VERY STUPID WAY!</p>
<p>The solution is to reference the view you&#8217;re displaying in by the UITabBarController like this:</p>
<pre><code>[sheet showInView:self.parentViewController.tabBarController.view];</code></pre>
<p>Freaking WOW!  Thanks a heap, Apple!</p>
<p>*grumble grumble*</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.kickasslabs.com%2F2010%2F07%2F03%2Fuiactionsheet-cancel-button-strange-behaviour%2F&amp;title=Quick%20Hits%3A%20UIActionSheet%20cancel%20button%20strange%20behaviour" id="wpa2a_2"><img src="http://www.kickasslabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.kickasslabs.com/2010/07/03/uiactionsheet-cancel-button-strange-behaviour/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quick Hits: Unit Testing iPhone Apps</title>
		<link>http://www.kickasslabs.com/2009/07/05/quick-hits-unit-testing-iphone-apps/</link>
		<comments>http://www.kickasslabs.com/2009/07/05/quick-hits-unit-testing-iphone-apps/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 19:04:35 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.kickasslabs.com/?p=381</guid>
		<description><![CDATA[I have a few things to add to the woefully incomplete official documentation on setting up automated tests in your iPhone apps: You need to add your main application executable target as a direct dependency of the test target, so &#8230; <a href="http://www.kickasslabs.com/2009/07/05/quick-hits-unit-testing-iphone-apps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have a few things to add to the woefully incomplete <a href="http://developer.apple.com/IPhone/library/documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html" title="iPhone Development Guide: Unit Testing Applications" target="iphonetestdocs">official documentation on setting up automated tests in your iPhone apps</a>:</p>
<ol>
<li>You need to add your main application executable target as a direct dependency of the test target, so that you&#8217;re always testing against your latest build.  Do this by double-clicking on the test target, going to the &#8220;General&#8221; pane in the properties dialog, and adding your app under &#8220;Direct Dependencies&#8221;.  (This was actually mentioned in the OCUnit tutorial for Cocoa, but not the one about iPhone testing.)</li>
<li>Your linker needs to know about the objects you&#8217;re testing.  An easy way to do this is to add the .m files for those classes to the &#8220;Compile Sources&#8221; group in your test target.  You&#8217;ll also have to make sure you link against any frameworks used by these objects.  (You could also tell your app target to export all symbols, then link your test target to it as you would a library.) (Thanks to Chris Hanson for pointing out this procedural improvement in comments.) <del datetime="2009-07-06T02:48:59+00:00">You need to explicitly link the object files of the classes you&#8217;re testing.  These are the &#8220;.o&#8221; files in your build folder.  To do this: Double-click on the test target, go to the &#8220;General&#8221; pane, add a new item under &#8220;Linked Libraries&#8221;.  In the dialog that pops up, choose &#8220;Add Other&#8230;&#8221; and add your class&#8217;s .o file.</del></li>
<li>When you run your tests, one failure looks like two:  Failed tests show up in Xcode as errors (just like compile errors, &#038;c). Any test failure triggers a second error, and you&#8217;ll see something like &#8220;Failed tests for architecture &#8216;i386&#8242; (GC OFF)&#8221;. The docs never say so, but this appears to be normal.  Fix the failing test, and it goes away.</li>
</ol>
<p>Anything else to add?  Drop us a comment!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.kickasslabs.com%2F2009%2F07%2F05%2Fquick-hits-unit-testing-iphone-apps%2F&amp;title=Quick%20Hits%3A%20Unit%20Testing%20iPhone%20Apps" id="wpa2a_4"><img src="http://www.kickasslabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.kickasslabs.com/2009/07/05/quick-hits-unit-testing-iphone-apps/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>UINavigationController Tricks</title>
		<link>http://www.kickasslabs.com/2009/07/03/uinavigationcontroller-tricks/</link>
		<comments>http://www.kickasslabs.com/2009/07/03/uinavigationcontroller-tricks/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 22:39:03 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.kickasslabs.com/?p=366</guid>
		<description><![CDATA[For an iPhone UI I&#8217;m developing, I need to have one UINavigationController nested inside another, and to have the inner UINavigationController&#8217;s events push a view on to the outer one&#8217;s stack. CocoaTouch didn&#8217;t give this to me for free, but &#8230; <a href="http://www.kickasslabs.com/2009/07/03/uinavigationcontroller-tricks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For an iPhone UI I&#8217;m developing, I need to have one UINavigationController nested inside another, and to have the inner UINavigationController&#8217;s events push a view on to the outer one&#8217;s stack.  CocoaTouch didn&#8217;t give this to me for free, but there <i>was</i> a simple solution.</p>
<p>This post assumes that you&#8217;re familiar with the fundamentals of iPhone programming, including view controllers, UINavigationController, and delegates.  There is <a href="http://www.kickasslabs.com/~kal_www/kickasslabs.com/wp-content/uploads/2009/07/navtest.tgz" title="UINavigationController Tricks sample code">sample code for this post</a>, which is released under version 2 of the <a href="http://sam.zoy.org/wtfpl/" title="WTFPL">WTFPL</a>.  </p>
<p><b>The Problem</b></p>
<p>I&#8217;m working on a multi-step UI for a game.  Expressing these steps as a regular drill-down table-style UI on the iPhone felt cumbersome, and games can&#8217;t afford for processes to feel cumbersome; people will stop playing.  One solution that occurred to me was batching related sets of steps in a smaller navigation table &#8211; so in Step 1 you&#8217;d drill through substeps 1A, 1B, and 1C before moving to Step 2.  The fact that the whole view wouldn&#8217;t be replaced with every choice seemed like it would be less destructive of the user&#8217;s mental context, and the chunking of substeps should make it easier for the users to wrap their heads around the process.  (No word yet on whether this solves my UI problem, but I like it so far.)</p>
<p>My UI solution contained its own technical problem, though: If I&#8217;m expressing the process steps in a UINavigationController, and expressing the substeps in a nested UINavigationController, how does the inner navigation controller notify the outer one that the user&#8217;s last substep choice completes that step and it&#8217;s time to move to the next step &#8211; or in programmatic terms, how does the inner UINavigationController tell the outer one to push a new view onto the outer one&#8217;s stack?</p>
<p>Or, putting it more visually, how do I get from here:</p>
<p><img src="http://www.kickasslabs.com/~kal_www/kickasslabs.com/wp-content/uploads/2009/07/navcontricks1.png" alt="navcontricks1" title="navcontricks1" width="414" height="770" class="aligncenter size-full wp-image-373" /></p>
<p>&#8230;to here:</p>
<p><img src="http://www.kickasslabs.com/~kal_www/kickasslabs.com/wp-content/uploads/2009/07/navcontricks2.png" alt="navcontricks2" title="navcontricks2" width="414" height="770" class="aligncenter size-full wp-image-374" /></p>
<p>In the non-nested situation when you wanted to push a new view onto a UINavigationController&#8217;s stack, you&#8217;d do the following in the current view:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>self.navigationController pushViewController<span style="color: #002200;">:</span>nextViewController animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>So in my nested case, I need to do that, but pushing onto the outer navigation controller&#8217;s stack from a view controller on the inner navigation controller&#8217;s stack.  I tried a number of naive (but sensible-seeming) targets for the pushViewController:animated: action, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.navigationController.navigationController
self.navigationController.parentViewController.navigationController</pre></div></div>

<p>Nothing worked.  I set a breakpoint and drilled down through the members of self.navigationController, and no path to that outer UINavigationController was apparent.</p>
<p><b>The Solution</b></p>
<p>While investigating the innards of UINavigationController, I stumbled upon a writable property that looked like it might help: The delegate.  When creating the inner UINavigationController, I added one line of code:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">innerNavCntlr.delegate <span style="color: #002200;">=</span> self; <span style="color: #11740a; font-style: italic;">// THIS IS THE MAGIC, PART 1</span></pre></div></div>

<p>Keep in mind that this is called in the view controller on top of the outer navigation controller&#8217;s stack, so &#8220;self&#8221; has access to the outer navigation controller.</p>
<p>When the view on top of my inner navigation controller&#8217;s stack is ready to signal the outer navigation controller, I do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// THIS IS THE MAGIC PART 2</span>
UIViewController <span style="color: #002200;">*</span>topVC <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UIViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>self.navigationController.delegate;
<span style="color: #002200;">&#91;</span>topVC.navigationController pushViewController<span style="color: #002200;">:</span>nextCntlr animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>A couple of notes:  First, the view controller that creates the inner UINavigationController must implement UINavigationControllerDelegate, or you&#8217;ll get a compiler warning &#8211; but you can just declare that it does so in the header file, as none of the methods in that interface are required.</p>
<p>Secondly: If you&#8217;re like me, this feels like an abuse of the delegate property.  Now there&#8217;s no reason that you couldn&#8217;t actually use that object productively as the inner navigation controller&#8217;s delegate &#8211; I just haven&#8217;t done so here.  And the fact that the delegate property has to be casted to be used this way says to me that it wasn&#8217;t meant for this &#8211; explicit casts are always a code smell.  (Anal-retentive types might want to put in some type-checking around that cast for safety.)</p>
<p>That said, it works, and I haven&#8217;t run into a maintainability problem yet, as this code doesn&#8217;t really get re-used in many places.  Were I expecting to use this trick often, I might package up a subclass of UINavigationController (call it NestedNavigationController) that actually took an outer UIViewController or UINavigationController property.  Then again I&#8217;m finding that in Cocoa, subclassing is often a code smell&#8230;</p>
<p>Got a better solution?  I&#8217;m interested &#8211; please leave a comment below!</p>
<p><b>Update:</b>  Whoops.  Comments are enabled now.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.kickasslabs.com%2F2009%2F07%2F03%2Fuinavigationcontroller-tricks%2F&amp;title=UINavigationController%20Tricks" id="wpa2a_6"><img src="http://www.kickasslabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.kickasslabs.com/2009/07/03/uinavigationcontroller-tricks/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

