<?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>Daniele Demichelis &#187; UIKit</title>
	<atom:link href="http://www.danidemi.com/mainwww/tag/uikit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danidemi.com/mainwww</link>
	<description>There are 10 types of people in the world: Those who understand binary, and those who don&#039;t...</description>
	<lastBuildDate>Wed, 14 Apr 2010 08:14:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone: how to select a UITabBarItem programmatically</title>
		<link>http://www.danidemi.com/mainwww/2009/11/iphone-how-to-select-a-uitabbaritem-programmatically/</link>
		<comments>http://www.danidemi.com/mainwww/2009/11/iphone-how-to-select-a-uitabbaritem-programmatically/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 11:22:31 +0000</pubDate>
		<dc:creator>danidemi</dc:creator>
				<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[UIKit]]></category>

		<guid isPermaLink="false">http://www.danidemi.com/mainwww/?p=61</guid>
		<description><![CDATA[<p>I&#8217;m working to an iPhone application with a TabBar on the footer area. Among the others there are a &#8220;Home&#8221; button and an &#8220;Account&#8221; button. The first allows the user to see a view that gives an overview of the application. The latter shows the view that the user uses to manage his/her account.</p>
<p>If the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working to an iPhone application with a TabBar on the footer area. Among the others there are a &#8220;Home&#8221; button and an &#8220;Account&#8221; button. The first allows the user to see a view that gives an overview of the application. The latter shows the view that the user uses to manage his/her account.</p>
<p>If the user is not currently logged in, in the &#8220;Home&#8221; view a warning message is displayed. There is also a button that is supposed to show the &#8220;Account&#8221; view. In that way it&#8217;s more clear for the user that he/she should log in.</p>
<p>How can you accomplish that task ? That post shows you the way I followed.</p>
<p>The big idea is to retrieve the TabBarController from the &#8220;Home&#8221; controller, and programmatically change the current view. To do that, the &#8220;Home&#8221; controller should get a reference to the TabBarController. But you can easily set that dependency in Interface Builder. You only need to provide a suited IBOutlet to the Home controller.</p>
<p>That is the tree structure of the controllers and views, as built in the interface builder.</p>
<p><a href="http://www.danidemi.com/mainwww/wp-content/uploads/2009/11/iphone_change_tabbar_programmatically_0.png"><img class="aligncenter size-full wp-image-62" title="iphone_change_tabbar_programmatically_0" src="http://www.danidemi.com/mainwww/wp-content/uploads/2009/11/iphone_change_tabbar_programmatically_0.png" alt="iphone_change_tabbar_programmatically_0" width="405" height="366" /></a></p>
<p>So, that&#8217;s an excerpt of the HomeController showing you only what is really needed to reach our goal. The goToRegistrationPage method will execute programmatically the switch to the account page.</p>
<pre>@interface HomeViewController : UIViewController {
UITabBarController *mainTabBarController;
}
@property(nonatomic, retain) IBOutlet UITabBarController *mainTabBarController;
-(IBAction) goToRegistrationPage;</pre>
<p>Now, we only need to set in Interface Builder the link between the the IBOutlet we just created and the Tab Bar Controller. Here&#8217;s the result.</p>
<p><a href="http://www.danidemi.com/mainwww/wp-content/uploads/2009/11/iphone_change_tabbar_programmatically_1.png"><img class="aligncenter size-full wp-image-63" title="iphone_change_tabbar_programmatically_1" src="http://www.danidemi.com/mainwww/wp-content/uploads/2009/11/iphone_change_tabbar_programmatically_1.png" alt="iphone_change_tabbar_programmatically_1" width="282" height="156" /></a>As you can see the mainTabBarController outlet is linked to the Tab Bar Controller we want to manage programmatically. That&#8217;s not difficult at all. Let&#8217;s give a look to the goToRegistrationPage method.</p>
<pre>-(IBAction) goToRegistrationPage {
 mainTabBarController.selectedIndex=3;
}</pre>
<p>Quite easy, isn&#8217;t it ?</p>
<p>Now the user click on the button on the Home view and he/she get exactly the same result of touching the tab bar button in the footer.</p>
<p>Hope you can find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danidemi.com/mainwww/2009/11/iphone-how-to-select-a-uitabbaritem-programmatically/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
