<?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>iphone.mitchallen.com &#187; github</title>
	<atom:link href="http://mitchallen.com/iphone/archives/tag/github/feed" rel="self" type="application/rss+xml" />
	<link>http://mitchallen.com/iphone</link>
	<description>random notes on iPhone development</description>
	<lastBuildDate>Tue, 10 Aug 2010 20:36:30 +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>Git Project Samples</title>
		<link>http://mitchallen.com/iphone/archives/361</link>
		<comments>http://mitchallen.com/iphone/archives/361#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:16:40 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=361</guid>
		<description><![CDATA[If you scroll to the bottom of my previous post you will notice that I&#8217;ve updated it with a new section: Git Clone If you have git installed, you can clone a copy of this project with the following command: git clone git://github.com/mitchallen/TestGame.git Going forward, I will attempt to post all sample code using git. Usually [...]]]></description>
			<content:encoded><![CDATA[<p>If you scroll to the bottom of my <a href="http://mitchallen.com/iphone/archives/304">previous post</a> you will notice that I&#8217;ve updated it with a new section:</p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px;"><strong>Git Clone</strong></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px;">If you have <strong>git</strong> installed, you can clone a copy of this project with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/mitchallen/TestGame.git</pre></div></div>

</blockquote>
<p>Going forward, I will attempt to post all sample code using git.  Usually this means that it will come wrapped in a full Xcode project.</p>
<p>I have several reasons for using git:</p>
<ul>
<li>I don&#8217;t have to wrestle with creating a zip file and uploading it to some obscure server somewhere</li>
<li>You don&#8217;t have to wrestle with downloading a zip file and expanding it somewhere</li>
<li>You don&#8217;t need an account to copy my public repositories</li>
<li>All you have to do is enter one line in a terminal window</li>
<li>You instantly end up with a local copy of the repository that you can copy and branch any which way you like</li>
<li>It forces you to think about source control <img src='http://mitchallen.com/iphone/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>If something is missing, I can just checkin new stuff and do a refresh</li>
<li>If I hack an existing project, I can just add a branch instead of forcing you and I to deal with multiple projects</li>
</ul>
<p>So if you still haven&#8217;t installed <strong>git</strong> on your Mac yet, I suggest you go back and <a href="http://mitchallen.com/iphone/archives/291">read my post on the subject</a> again.  Also if you have, you may want to read it again.  I&#8217;ve added a few more links and info on filtering out certain files to keep your repository from getting cluttered.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/361/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Started with the Cocos2D Game Engine</title>
		<link>http://mitchallen.com/iphone/archives/304</link>
		<comments>http://mitchallen.com/iphone/archives/304#comments</comments>
		<pubDate>Wed, 16 Sep 2009 17:22:19 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[game engines]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=304</guid>
		<description><![CDATA[Introduction What follows are notes that I gathered from looking at various tutorials on getting started with the Cocos2D Game Engine. You can find the tutorials that I used as a source for my notes here: http://monoclestudios.com/cocos2d_whitepaper.html http://morethanmachine.com/macdev/?p=83 Additional links may be found in my entry here: http://mitchallen.com/iphone/archives/254 This tutorial was tested with cocos2d-iphone-0.8 &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>What follows are notes that I gathered from looking at various tutorials on getting started with the Cocos2D Game Engine. You can find the tutorials that I used as a source for my notes here:</p>
<ul>
<li><a title="http://monoclestudios.com/cocos2d_whitepaper.html" href="http://monoclestudios.com/cocos2d_whitepaper.html">http://monoclestudios.com/cocos2d_whitepaper.html</a></li>
<li><a title="http://morethanmachine.com/macdev/?p=83" href="http://morethanmachine.com/macdev/?p=83">http://morethanmachine.com/macdev/?p=83</a></li>
</ul>
<p>Additional links may be found in my entry here:</p>
<ul>
<li><a title="http://mitchallen.com/iphone/archives/254" href="http://mitchallen.com/iphone/archives/254">http://mitchallen.com/iphone/archives/254</a></li>
</ul>
<p>This tutorial was tested with cocos2d-iphone-0.8 &#8211;  I had trouble compiling with 0.8.<strong>1</strong>.</p>
<p><strong>UPDATE</strong>: I&#8217;ve added some notes for compiling using 0.8.2 &#8211; with the help of some reader comments below.</p>
<p><strong>Build Options</strong></p>
<p>There are a number of options for creating a Cocos2D Game Project:</p>
<ol>
<li>Use the engine as a shared library</li>
<li>Start from a template</li>
<li>Copy the engine components and put them in your project</li>
</ol>
<p>For simplicity this article covers Option #3 &#8211; copying the engine components to your project.</p>
<p>If you would like to know more about the other options, see these links:</p>
<ul>
<li><a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/">http://www.clintharris.net/2009/iphone-app-shared-libraries/</a></li>
<li><a href="http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/">http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/</a></li>
</ul>
<p><strong>Setting Up the Project</strong></p>
<ul>
<li>Download and unpack the latest <em>stable</em> release of the Cocos2D Game Engine from here: <a href="http://code.google.com/p/cocos2d-iphone/">http://code.google.com/p/cocos2d-iphone/</a></li>
<li>Launch Xcode</li>
<li>Select: <strong>File / New Project &#8230; / [<em>iPhone OS : Application</em></strong><strong>] / Window-based Application / Choose &#8230;</strong></li>
<li><strong>Save As</strong>: <em>TestGame</em>, <strong>Save</strong></li>
<li>Delete: <em>Resources / MainWindow.xib</em></li>
<li>Edit: <em>TestGame-Info.plist</em>:</li>
<li>Delete the line: <strong>Main nib file base name : MainWindow</strong></li>
<li>Add the line: <strong>Status bar is initially hidde</strong><strong>n</strong> &#8211; and check it</li>
<li>Save the file</li>
<li>Click on the <em>TestGame</em> folder icon at the top of the <strong>Groups &amp; Files</strong> pane</li>
<li>Select: <strong>Project / Add to Project &#8230;</strong> / <em>cocos2d-phone-<strong>x.y.z </strong>/ cocos2d</em></li>
<li>Hold down the <strong>Apple-key</strong> and also select: <em>external</em></li>
<li>Click: <strong>Add</strong></li>
<li>Check: <strong>Copy items in destination group&#8217;s folder (if needed)</strong></li>
<li>Click: <strong>Recursively create groups for any added folders</strong></li>
<li>Click: <strong>Add</strong></li>
<li>Note that if you mess up and need to delete the folders, you also may have to go to the project folder itself and delete them.  Otherwise you may get an error if trying to add them again.</li>
<li>In the <em>external</em> folder, delete everything that is <strong>NOT</strong> the <em><strong>Chipmunk</strong></em> folder (if you are using 0.8.2 keep the <strong>FontLabel</strong> folder too!).  Why?  Because some of those items are experimental and may not compile.</li>
<li>From within the <em>external / Chipmunk</em> folder, delete everything that is <strong>NOT</strong> the <em><strong>src</strong></em> folder.</li>
<li>Right-click on the <em>Resources</em> folder and select: <strong>Add / Existing Files &#8230;</strong></li>
<li>If using 0.8: <em>cocos2d / Resources / <strong>Images</strong> / fps_images.png</em></li>
<li>If using 0.8.2: <em>cocos2d / Resources / <strong>Fonts</strong> / fps_images.png</em></li>
<li><strong>Add</strong> / Check <strong>Copy &#8230;</strong>, <strong>Recursive &#8230;</strong>, <strong>Add</strong></li>
<li>Right-click on the <em>Frameworks</em> folder and select: <strong>Add / Existing Frameworks &#8230;</strong></li>
<li>Select the <em>Frameworks</em> folder</li>
<li>Select: <strong>OpenGLES.framework</strong></li>
<li>Click <strong>Shift</strong> and also select: <strong>QuartzCore.framework</strong> and click: <strong>Add</strong>, click <strong>Add</strong> again</li>
</ul>
<p><strong>Additional Steps for 0.8.2</strong></p>
<p>If you are using 0.8.2 (or possibly a later version) you will need to also do the following steps to get the project to compile:</p>
<ul>
<li>Double-click on <strong>Targets \ TestGame</strong></li>
<li>Make sure that the <strong>General</strong> tab is selected in the dialog box</li>
<li>There are two sets of <strong>+  / -</strong> buttons in the dialog, click the <strong>+</strong> button on the bottom under the list of <strong>Linked Librarie</strong>s</li>
<li>Select <strong>libz.1.2.3.dylib</strong> and <strong>Add</strong> it
</ul>
<p><strong>Add New Files</strong></p>
<ul>
<li>Right-click on the <em>Classes</em> folder and select:</li>
<li><strong>Add / New File &#8230; / </strong>[<strong><em>iPhone OS : Cocoa Touch Class</em></strong> ] / <strong>Object-C class</strong> / [<strong><em>NSObject</em></strong>] / <strong>Next</strong></li>
<li><strong>File Name: </strong><em>TestScene.m</em>, leave <strong>Also create &#8220;TestScene.h</strong><em>&#8220;</em> checked and click <strong>Finish</strong></li>
</ul>
<p>Make the following changes to <strong>Classes / TestScene.h</strong>:</p>
<ul>
<li>Remove the line:  <em>#import &lt;Foundation/Foundation.h&gt; </em></li>
<li>Add the following import lines:</li>
<li><strong>#import &lt;UIKit/UIKit.h&gt;</strong></li>
<li><strong>#import &#8220;cocos2d.h&#8221;</strong></li>
<li><strong>#import &#8220;chipmunk.h&#8221;</strong></li>
<li>Change the class definition so that it is based on <strong>Scene</strong> instead of <strong>NSObject</strong></li>
<li>At the bottom of the file add another <strong>@interface</strong> called <strong>TestLayer</strong> based on <strong>Layer</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestScene.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import</span>
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
<span style="color: #6e371a;">#import &quot;chipmunk.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestScene <span style="color: #002200;">:</span> Scene <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer <span style="color: #002200;">:</span> Layer <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Make the following changes to <strong>Classes / TestScene.m</strong>:</p>
<ul>
<li>Add <strong>init</strong> method that adds a <strong>TestLayer</strong> to the scene</li>
<li>Add an <strong>@implementation</strong> for <strong>TestLayer</strong></li>
<li>Add <strong>init</strong> method to <strong>TestLayer</strong> that puts something on the screen</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestScene.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestScene
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>TestLayer node<span style="color: #002200;">&#93;</span> z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestLayer
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">// Note that if you spell the fontName wrong, the label won't appear.</span>
		Label <span style="color: #002200;">*</span>test <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Label labelWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello World&quot;</span> fontName<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica&quot;</span> fontSize<span style="color: #002200;">:</span> <span style="color: #2400d9;">24</span><span style="color: #002200;">&#93;</span>;
		test.position <span style="color: #002200;">=</span> cpv<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">240</span><span style="color: #002200;">&#41;</span>;	<span style="color: #11740a; font-style: italic;">// cpv = Chipmunk vector</span>
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> test<span style="color: #002200;">&#93;</span>;	<span style="color: #11740a; font-style: italic;">// Add the label to the layer.</span>
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Edit the Existing Files</strong></p>
<p>Make the following changes to <strong>Classes / TestGameAppDelegate.h</strong>:</p>
<ul>
<li>Add two #import statements:</li>
<li><strong>#import &#8220;cocos2d.h&#8221;</strong></li>
<li><strong>#import &#8220;TestScene.h&#8221;</strong></li>
<li>Remove the two lines referencing the <strong>window</strong> property</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestGameAppDelegate.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestGameAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>  <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Make the following changes to <strong>Classes / TestGameAppDelegate.m</strong>:</p>
<ul>
<li>Remove the line: <em>@synthesize window;</em></li>
<li>Remove the <strong>dealloc</strong> method</li>
<li>Clear the contents of the method: <strong>applicationDidFinishLaunching</strong> and replace it with the code below</li>
<li>If you don&#8217;t want your game to start in landscape mode, comment out the line containing <strong>setDeviceOrientation</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestGameAppDelegate.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestGameAppDelegate.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestGameAppDelegate
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span> 
&nbsp;
	UIWindow <span style="color: #002200;">*</span>window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>window setUserInteractionEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>window setMultipleTouchEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// DEPRECATED: [[Director sharedDirector] setLandscape: YES];</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setDeviceOrientation<span style="color: #002200;">:</span> CCDeviceOrientationLandscapeLeft <span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> attachInWindow<span style="color: #002200;">:</span> window<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
	TestScene <span style="color: #002200;">*</span>game <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>TestScene node<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> runWithScene<span style="color: #002200;">:</span> game<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Make the following changes to <strong>Other Sources / main.m</strong>:</p>
<ul>
<li>Change the last argument in the call to <strong>UIApplicationMain</strong> to a string containing the name of the delegate: <strong>@&#8221;TestGameAppDelegate&#8221;</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  main.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #400080;">NSAutoreleasePool</span> <span style="color: #002200;">*</span> pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// MCA - changed last argument to name of delegate.</span>
    <span style="color: #a61390;">int</span> retVal <span style="color: #002200;">=</span> UIApplicationMain<span style="color: #002200;">&#40;</span>argc, argv, <span style="color: #a61390;">nil</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TestGameAppDelegate&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>pool release<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> retVal;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Compile and Run</strong></p>
<ul>
<li>Click: <strong>Build and Go</strong></li>
</ul>
<p><strong>Git Clone</strong></p>
<p>If you have <strong>git</strong> installed, you can clone a copy of this project with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/mitchallen/TestGame.git</pre></div></div>

<p>For my next tutorial I will be adding code to the repository.  So to get back to the original state of this tutorial, you will need to execute the following at the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git checkout v100</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/304/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Changing the display size of a UITableView</title>
		<link>http://mitchallen.com/iphone/archives/184</link>
		<comments>http://mitchallen.com/iphone/archives/184#comments</comments>
		<pubDate>Tue, 26 May 2009 21:11:27 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[UITableViewController]]></category>
		<category><![CDATA[UIViewController]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=184</guid>
		<description><![CDATA[UPDATE 29-Apr-2010: By popular demand, here is a git repository with an updated sample: git clone git@github.com:mitchallen/TableSize2.git Note that I have NOT updated the code in this post. Look at the repository for the new code. This new sample fixes two issues: missing IBOutlet and the deprecated setText method on the cell. To see how [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE 29-Apr-2010:</strong></p>
<p>By popular demand, here is a git repository with an updated sample:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git@github.com:mitchallen/TableSize2.git</pre></div></div>

<p>Note that I have NOT updated the code in this post.  Look at the repository for the new code.  This new sample fixes two issues:  missing IBOutlet and the deprecated setText method on the cell.</p>
<p>To see how it looks in &#8220;boxed&#8221; mode on the iPad, set the compiler to: Simulator &#8211; 3.2 | Debug.</p>
<p><a href="http://mitchallen.com/iphone/wp-content/uploads/2009/05/Screen-shot-2010-04-29-at-10.36.44-PM.png"><img class="alignnone size-medium wp-image-547" title="Screen shot 2010-04-29 at 10.36.44 PM" src="http://mitchallen.com/iphone/wp-content/uploads/2009/05/Screen-shot-2010-04-29-at-10.36.44-PM-231x300.png" alt="" width="231" height="300" /></a></p>
<hr size="1" /><strong>ORIGINAL POST</strong></p>
<p>Here is an example of how to create a view that contains a <strong>UITableView</strong> that doesn&#8217;t take over the whole screen.  An example of an application that uses a small table is the <strong>Stocks</strong> application that comes with the iPhone / iPod Touch.  You may think you need a <strong>UITableViewController</strong> &#8211; but that only gets in the way and takes over the view.</p>
<ul>
<li>Create a View-based iPhone application and call it <strong><em>TableSize1</em></strong></li>
<li>Modify <strong><em>TableSize1ViewController.h</em></strong> so that it looks like this:</li>
</ul>
<p><strong>TableSize1ViewController.h</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1ViewController.h</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 5/26/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #a61390;">@interface</span> TableSize1ViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
&nbsp;
	UITableView <span style="color: #002200;">*</span>tableView;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>retain, nonatomic<span style="color: #002200;">&#41;</span> UITableView <span style="color: #002200;">*</span>tableView;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<ul>
<li>Modify <strong><em>TableSize1ViewController.m</em></strong> so that it looks like this:</li>
</ul>
<p><strong>TableSize1ViewController.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1ViewController.m</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 5/26/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TableSize1ViewController.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TableSize1ViewController
&nbsp;
<span style="color: #a61390;">@synthesize</span> tableView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">1</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">20</span>;  <span style="color: #11740a; font-style: italic;">// Test hack to display multiple rows.</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectZero reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>szCell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithFormat<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Row %i&quot;</span>, indexPath.row <span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>cell setText<span style="color: #002200;">:</span>szCell<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>szCell release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Set up the cell</span>
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Navigation logic -- create and push a new view controller</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>didReceiveMemoryWarning <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super didReceiveMemoryWarning<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// Releases the view if it doesn't have a superview</span>
    <span style="color: #11740a; font-style: italic;">// Release anything that's not essential, such as cached data</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<ul>
<li>In the <strong>Resources</strong> folder, double-click <strong>TableSize1ViewController.xib</strong> to launch <strong>Interface Builder</strong></li>
<li>From <strong>Library / Cocoa Touch Plugin / Data Views</strong> drag a <strong>Table View</strong> on to the <strong>View</strong> and make it about half the height of the view (Select <strong>Tools / Library</strong> from the main menu if it isn&#8217;t visible)</li>
<li>Click on the new <strong>Table View</strong></li>
<li>Click on the second tab in the <strong>Inspector</strong> window (Select <strong>Tools / Inspector</strong> from the main menu if it isn&#8217;t visible)</li>
<li>After clicking the second tab, the title of the <strong>Inspector</strong> window should be <strong>Table View Connections</strong></li>
<li>Under <strong>Outlets</strong>: for both <strong>dataSource</strong> and <strong>delegate</strong>, drag the mouse from the circles next to them to the <strong>File&#8217;s Owner</strong> icon in the <strong>TableSize1ViewController.xib</strong> window.</li>
<li>Under <strong>Referencing Outlets</strong>: drag from <strong>New Referencing Outlet</strong> to the <strong>File&#8217;s Owner</strong> icon and select <strong>tableView</strong>.</li>
<li>With <strong>Interface Builder</strong> in focus, select <strong>File / Save</strong></li>
<li>Go back to your project window and click <strong>Build and Go</strong></li>
<li>Your application should now display a table that only takes up half the screen.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/184/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
