<?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>Hans Pinckaers &#187; uinavigationcontroller</title>
	<atom:link href="http://www.hanspinckaers.com/category/uinavigationcontroller/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hanspinckaers.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 17 Jul 2010 11:08:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom action on Back Button UINavigationController</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller</link>
		<comments>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller#comments</comments>
		<pubDate>Fri, 27 Nov 2009 22:17:05 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[uinavigationcontroller]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160</guid>
		<description><![CDATA[Yes! There is a way of using the backBarButton with a custom action. No, it’s not by overriding the backBarButton property of navigationItem. This is not an ugly solution with images that simulate the &#8220;Back&#8221;-button (arrow-shaped.) It’s possible to use the backBarButton for popping the current viewController as normal, but than with other animations such [...]]]></description>
			<content:encoded><![CDATA[<p>Yes! There is a way of using the backBarButton with a custom action. No, it’s not by overriding the backBarButton property of navigationItem. This is not an ugly solution with images that simulate the &#8220;Back&#8221;-button (arrow-shaped.) It’s possible to use the backBarButton for popping the current viewController as normal, but than with other animations such as UIViewAnimationTransitionCurlDown.<span id="more-160"></span></p>
<p>Enough said, the solution is simple. You have to subclass your navigationController&#8217;s  popViewControllerAnimated:(BOOL)animated. So create a custom navigationController:</p>
<h3>customNavigationController.h</h3>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
<span style="color: #a61390;">@interface</span> customNavigationController <span style="color: #002200;">:</span> UINavigationController <span style="color: #002200;">&#123;</span><span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>And a custom &#8220;popViewControllerAnimated:(BOOL)animated&#8221;, this popViewControllerAnimated-function uses the &#8220;UIViewAnimationTransitionCurlDown&#8221; when popping from a SettingsTableView.</p>
<h3>customNavigationController.m</h3>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;customNavigationController.h&quot;</span>
<span style="color: #6e371a;">#import &quot;SettingsTableController.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> customNavigationController
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>popViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self.viewControllers lastObject<span style="color: #002200;">&#93;</span> class<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #002200;">&#91;</span>SettingsTableController class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
&nbsp;
		<span style="color: #002200;">&#91;</span>UIView beginAnimations<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> context<span style="color: #002200;">:</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>UIView setAnimationDuration<span style="color: #002200;">:</span> <span style="color: #2400d9;">1.00</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>UIView setAnimationTransition<span style="color: #002200;">:</span>UIViewAnimationTransitionCurlDown
					forView<span style="color: #002200;">:</span>self.view cache<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		UIViewController <span style="color: #002200;">*</span>viewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super popViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #002200;">&#91;</span>UIView commitAnimations<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #a61390;">return</span> viewController;
	<span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>super popViewControllerAnimated<span style="color: #002200;">:</span>animated<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Use your custom navigationController in your appDelegate:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">customNavigationController <span style="color: #002200;">*</span>navigationController <span style="color: #002200;">=</span>
 <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>customNavigationController alloc<span style="color: #002200;">&#93;</span> 
		initWithRootViewController<span style="color: #002200;">:</span>rootView<span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
