<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Custom action on Back Button UINavigationController</title>
	<atom:link href="http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller</link>
	<description></description>
	<lastBuildDate>Sun, 25 Dec 2011 03:09:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Dave</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-344</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sat, 26 Nov 2011 00:53:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-344</guid>
		<description>Great tip.  Based on the suggestion of subclassing UINavigationController, I was able to very easily implement my own subclass, that allows me to conditionally call popToController:Animated: instead of popViewControllerAnimated.   I added a property to my controller suclass, so that when set, I skip to the set viewController, rather than doing a normal pop.

This allows me to implement in-between views that act like menus in desktop apps, and then skip over those views as I pop the view off the stack that the user selected from the menu view.  The look and feel is much better now, as the user doesn&#039;t see the menu view ask I pop views. :-)</description>
		<content:encoded><![CDATA[<p>Great tip.  Based on the suggestion of subclassing UINavigationController, I was able to very easily implement my own subclass, that allows me to conditionally call popToController:Animated: instead of popViewControllerAnimated.   I added a property to my controller suclass, so that when set, I skip to the set viewController, rather than doing a normal pop.</p>
<p>This allows me to implement in-between views that act like menus in desktop apps, and then skip over those views as I pop the view off the stack that the user selected from the menu view.  The look and feel is much better now, as the user doesn&#8217;t see the menu view ask I pop views. <img src='http://www.hanspinckaers.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: simon</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-332</link>
		<dc:creator>simon</dc:creator>
		<pubDate>Mon, 03 Oct 2011 13:40:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-332</guid>
		<description>you&#039;re the best, for the second time.
Keep&#039;em coming.</description>
		<content:encoded><![CDATA[<p>you&#8217;re the best, for the second time.<br />
Keep&#8217;em coming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ginny</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-329</link>
		<dc:creator>Ginny</dc:creator>
		<pubDate>Sat, 17 Sep 2011 09:25:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-329</guid>
		<description>To Jules or anyone else who happens upon this page:  I also needed a &quot;are you sure you want to quit?&quot; on the back button for my app. Here&#039;s how I implemented it.  Tricky but possible!

Turns out if you implement the UINavigationBarDelegate in the CustomNavigationController, you can make use of the shouldPopItem method:

----------------------------------------------------

CustomNavigationController.h  :

#import 


@interface CustomNavigationController : UINavigationController  {

	BOOL alertViewClicked;
	BOOL regularPop;
}

@end


----------------------------------------------------
CustomNavigationController.m :

#import &quot;CustomNavigationController.h&quot;
#import &quot;SettingsTableController.h&quot;


@implementation CustomNavigationController


- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
	
	if (regularPop) {
		regularPop = FALSE;
		return YES;
	}
	
	if (alertViewClicked) {
		alertViewClicked = FALSE;
		return YES;
	}
	
	if ([self.topViewController isMemberOfClass:[SettingsTableViewController class]]) {
		UIAlertView * exitAlert = [[[UIAlertView alloc] initWithTitle:@&quot;Are you sure you want to quit?&quot; 
															  message:nil delegate:self cancelButtonTitle:@&quot;Cancel&quot; otherButtonTitles:@&quot;Yes&quot;, nil] autorelease];
		
		[exitAlert show];
		
		return NO;
		
	}	
	else {
		regularPop = TRUE;
		[self popViewControllerAnimated:YES];
		return NO;
	}	
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
		if (buttonIndex == 0) {
			//Cancel button
		}
		
		else if (buttonIndex == 1) {	
		        //Yes button
			alertViewClicked = TRUE;
			[self popViewControllerAnimated:YES];
		}		
	
}
@end
----------------------------------------------------
The weird logic with the &quot;regularPop&quot; bool is because for some reason just returning &quot;YES&quot; on shouldPopItem only pops the navbar, not the view associated with the navBar - for that to happen you have to directly call popViewControllerAnimated (which then calls shouldPopItem as part of its logic.)</description>
		<content:encoded><![CDATA[<p>To Jules or anyone else who happens upon this page:  I also needed a &#8220;are you sure you want to quit?&#8221; on the back button for my app. Here&#8217;s how I implemented it.  Tricky but possible!</p>
<p>Turns out if you implement the UINavigationBarDelegate in the CustomNavigationController, you can make use of the shouldPopItem method:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>CustomNavigationController.h  :</p>
<p>#import </p>
<p>@interface CustomNavigationController : UINavigationController  {</p>
<p>	BOOL alertViewClicked;<br />
	BOOL regularPop;<br />
}</p>
<p>@end</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
CustomNavigationController.m :</p>
<p>#import &#8220;CustomNavigationController.h&#8221;<br />
#import &#8220;SettingsTableController.h&#8221;</p>
<p>@implementation CustomNavigationController</p>
<p>- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {</p>
<p>	if (regularPop) {<br />
		regularPop = FALSE;<br />
		return YES;<br />
	}</p>
<p>	if (alertViewClicked) {<br />
		alertViewClicked = FALSE;<br />
		return YES;<br />
	}</p>
<p>	if ([self.topViewController isMemberOfClass:[SettingsTableViewController class]]) {<br />
		UIAlertView * exitAlert = [[[UIAlertView alloc] initWithTitle:@&#8221;Are you sure you want to quit?&#8221;<br />
															  message:nil delegate:self cancelButtonTitle:@&#8221;Cancel&#8221; otherButtonTitles:@&#8221;Yes&#8221;, nil] autorelease];</p>
<p>		[exitAlert show];</p>
<p>		return NO;</p>
<p>	}<br />
	else {<br />
		regularPop = TRUE;<br />
		[self popViewControllerAnimated:YES];<br />
		return NO;<br />
	}<br />
}</p>
<p>-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {<br />
		if (buttonIndex == 0) {<br />
			//Cancel button<br />
		}</p>
<p>		else if (buttonIndex == 1) {<br />
		        //Yes button<br />
			alertViewClicked = TRUE;<br />
			[self popViewControllerAnimated:YES];<br />
		}		</p>
<p>}<br />
@end<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
The weird logic with the &#8220;regularPop&#8221; bool is because for some reason just returning &#8220;YES&#8221; on shouldPopItem only pops the navbar, not the view associated with the navBar &#8211; for that to happen you have to directly call popViewControllerAnimated (which then calls shouldPopItem as part of its logic.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bob</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-278</link>
		<dc:creator>bob</dc:creator>
		<pubDate>Sat, 09 Jul 2011 02:44:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-278</guid>
		<description>if([[self.viewControllers lastObject] class] == [SettingsTableController class])
should be written as
if([self.topViewController isMemberOfClass:[SettingsTableController class]])</description>
		<content:encoded><![CDATA[<p>if([[self.viewControllers lastObject] class] == [SettingsTableController class])<br />
should be written as<br />
if([self.topViewController isMemberOfClass:[SettingsTableController class]])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: loosy</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-160</link>
		<dc:creator>loosy</dc:creator>
		<pubDate>Fri, 28 Jan 2011 13:44:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-160</guid>
		<description>From Apple documentation &quot;This (UINavigationController) class is not intended for subclassing. Instead, you use instances of it as-is in situations where you want your application’s user interface to reflect the hierarchical nature of your content.&quot;

here is reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

so what could be another way of achieving this.</description>
		<content:encoded><![CDATA[<p>From Apple documentation &#8220;This (UINavigationController) class is not intended for subclassing. Instead, you use instances of it as-is in situations where you want your application’s user interface to reflect the hierarchical nature of your content.&#8221;</p>
<p>here is reference:<br />
<a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html" rel="nofollow">http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html</a></p>
<p>so what could be another way of achieving this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-153</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Sun, 19 Dec 2010 17:35:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-153</guid>
		<description>You&#039;re a genius! :-)  Thank you for the code and the details!</description>
		<content:encoded><![CDATA[<p>You&#8217;re a genius! <img src='http://www.hanspinckaers.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Thank you for the code and the details!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jornando Júnior</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-152</link>
		<dc:creator>Jornando Júnior</dc:creator>
		<pubDate>Wed, 15 Dec 2010 12:26:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-152</guid>
		<description>Simple and Perfect!
Tnk&#039;s a lot!!!</description>
		<content:encoded><![CDATA[<p>Simple and Perfect!<br />
Tnk&#8217;s a lot!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CedricSoubrie</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-149</link>
		<dc:creator>CedricSoubrie</dc:creator>
		<pubDate>Fri, 10 Dec 2010 11:09:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-149</guid>
		<description>Excellent, clean and easy. Thx !</description>
		<content:encoded><![CDATA[<p>Excellent, clean and easy. Thx !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 骨头鱼的墓 &#187; 修改NavigationController的后退按钮Action</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-148</link>
		<dc:creator>骨头鱼的墓 &#187; 修改NavigationController的后退按钮Action</dc:creator>
		<pubDate>Fri, 03 Dec 2010 12:01:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-148</guid>
		<description>[...] 原文：Custom action on Back Button UINavigationController    分类: iPhone OS 标签:         评论 (0) Trackbacks (0) 发表评论 Trackback [...]</description>
		<content:encoded><![CDATA[<p>[...] 原文：Custom action on Back Button UINavigationController    分类: iPhone OS 标签:         评论 (0) Trackbacks (0) 发表评论 Trackback [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Intercepting UINavigationController back button &#171; Web • log?</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/comment-page-1#comment-131</link>
		<dc:creator>Intercepting UINavigationController back button &#171; Web • log?</dc:creator>
		<pubDate>Wed, 06 Oct 2010 02:34:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=160#comment-131</guid>
		<description>[...] intercept the back button, I searched the net to find a solution. One of the top hits suggests subclassing UINavigationController and overriding - [UIViewController [...]</description>
		<content:encoded><![CDATA[<p>[...] intercept the back button, I searched the net to find a solution. One of the top hits suggests subclassing UINavigationController and overriding &#8211; [UIViewController [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

