<?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>KevFoo &#187; iphone</title>
	<atom:link href="http://blog.kevfoo.com/index.php/category/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kevfoo.com</link>
	<description>The weblog of a Chicago based .Net and iPhone developer.</description>
	<lastBuildDate>Wed, 26 May 2010 13:33:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>iPhone Wireframes</title>
		<link>http://blog.kevfoo.com/index.php/2010/02/iphone-wireframes/</link>
		<comments>http://blog.kevfoo.com/index.php/2010/02/iphone-wireframes/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 04:10:45 +0000</pubDate>
		<dc:creator>Kevin McMahon</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[wireframes]]></category>
		<category><![CDATA[Aesthetics]]></category>
		<category><![CDATA[Blank Side]]></category>
		<category><![CDATA[Blogs]]></category>
		<category><![CDATA[Cards]]></category>
		<category><![CDATA[Flexibility]]></category>
		<category><![CDATA[Notecards]]></category>
		<category><![CDATA[Personal Preference]]></category>
		<category><![CDATA[Prioritize]]></category>
		<category><![CDATA[Rough Dimensions]]></category>
		<category><![CDATA[Screens]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Ui]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Visual Spatial Learner]]></category>

		<guid isPermaLink="false">http://blog.kevfoo.com/index.php/2010/02/iphone-wireframes/</guid>
		<description><![CDATA[I stumbled across a great collection of iPhone wireframe templates tonight while going through my feeds.&#160; It got me thinking about the process I’ve been using to layout and design the app I am working on.
I’ve been using regular 3 x 5’ notecards to sketch out different screens for the iPhone app I am working [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled across a great collection of <a href="http://www.geekchix.org/blog/2010/01/03/a-collection-of-printable-sketch-templates-and-sketch-books-for-wireframing/#mobi">iPhone wireframe templates</a> tonight while going through my feeds.&#160; It got me thinking about the process I’ve been using to layout and design the app I am working on.</p>
<p>I’ve been using regular 3 x 5’ notecards to sketch out different screens for the iPhone app I am working on.&#160; On the ruled side I’ll scribble notes and call out must/should/wish components of the screens to help prioritize features.&#160; On the blank side I’ve been sketching out wireframes of the screens to help get a feel for the UI and flow of the app.</p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2010/02/cards_laid_out.jpg"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="cards_laid_out" border="0" alt="cards_laid_out" src="http://blog.kevfoo.com/wp-content/uploads/2010/02/cards_laid_out_thumb.jpg" width="244" height="184" /></a> </p>
<p>I’ve played around with <a href="http://www.balsamiq.com/">Balsamiq</a> and, while the tool is fantastic, I find myself still partial to the notecards.&#160; With the same rough dimensions of the iPhone and the flexibility of being able to quickly rearrange and reorder the screens, the cards suit my preferences as a visual-spatial learner well.&#160; </p>
<p>As with most tools and techniques, personal preference plays a large role in how and when they’re employed.&#160; I always enjoy checking out how other people work and try and <strike>steal</strike> glean ideas from them.&#160; I’ve found the following blogs pretty useful for design, usability, and UX.&#160; I hope they help inspire you to create something cool.</p>
<p><a href="http://wireframes.tumblr.com/">I ♥ wireframes</a><br/> <a href="http://infosthetics.com/">information aesthetics</a><br/> <a href="http://www.everydayux.com/">everydayUX</a><br/> <a href="http://sender11.typepad.com/sender11/">Sender 11</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kevfoo.com/index.php/2010/02/iphone-wireframes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monotouch: UIAlertView + UITextField = Crazy Delicious</title>
		<link>http://blog.kevfoo.com/index.php/2009/11/monotouch-uialertview-uitextfield-crazy-delicious/</link>
		<comments>http://blog.kevfoo.com/index.php/2009/11/monotouch-uialertview-uitextfield-crazy-delicious/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 17:20:15 +0000</pubDate>
		<dc:creator>Kevin McMahon</dc:creator>
				<category><![CDATA[UIAlertView]]></category>
		<category><![CDATA[UITextField]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Button Setup]]></category>
		<category><![CDATA[Cancel Button]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Configured]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Default Button]]></category>
		<category><![CDATA[Itunes]]></category>
		<category><![CDATA[Message Label]]></category>
		<category><![CDATA[New Control]]></category>
		<category><![CDATA[Stock Control]]></category>
		<category><![CDATA[Two Ways]]></category>
		<category><![CDATA[Ui]]></category>

		<guid isPermaLink="false">http://blog.kevfoo.com/index.php/2009/11/monotouch-uialertview-uitextfield-crazy-delicious/</guid>
		<description><![CDATA[If you have ever tried to buy or install anything from the App Store or iTunes on your iPhone, then you certainly have been prompted for your password by a screen that looks like this:
 
The control used by Apple to prompt you for your password isn’t available out-of-the-box in Cocoa Touch, but fortunately it [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever tried to buy or install anything from the App Store or iTunes on your iPhone, then you certainly have been prompted for your password by a screen that looks like this:</p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/itunes_pw_iphone.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="itunes_pw_iphone" border="0" alt="itunes_pw_iphone" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/itunes_pw_iphone_thumb.jpg" width="164" height="244" /></a> </p>
<p>The control used by Apple to prompt you for your password isn’t available out-of-the-box in Cocoa Touch, but fortunately it is pretty easy to roll your own.&#160; I’ve put together a <a href="http://github.com/kevinmcmahon/CustomUITextFieldAlertView">sample project</a> that shows a couple different techniques that are available for creating and customizing the control, and I’ll go over a few of them here.</p>
<p>The stock <a href="http://www.go-mono.com/docs/index.aspx?link=T%3AMonoTouch.UIKit.UIAlertView%2FP">UIAlertView</a> control consists of a title label, message label, and typically one or more buttons.&#160; It is important to note that in Monotouch, a default button setup isn’t configured, and buttons have to be added explicitly.&#160; If a UIAlertView is configured without any buttons, then dismissing the control will have to be done programmatically because the user will have no way to dismiss the control.&#160; In both of my examples I’ve configured the control to have two buttons (Cancel and Ok), but I could have gotten by with just one.&#160; If only one button is used, it is important to also note that the button is considered the Cancel button by the control, and the <b><a href="http://www.go-mono.com/docs/monodoc.ashx?link=P%3aMonoTouch.UIKit.UIAlertView.CancelButtonIndex">CancelButtonIndex</a></b> property will refer to that button. </p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/Basic_UIAlertView.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Basic_UIAlertView" border="0" alt="Basic_UIAlertView" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/Basic_UIAlertView_thumb.png" width="244" height="121" /></a></p>
<p>The easiest way to go about composing a UIAlertView with a <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T%3aMonoTouch.UIKit.UITextField">UITextField</a> is to create an instance of a UITextField and add it as a sub-view.&#160; Since you’re adding a layer on top of UIAlertView’s view, the key will be fitting this new control into the UI.&#160; There are two ways of going about this.&#160; The first and maybe most obvious way to solve this problem is to make some room between the message label and buttons for the text field ala the iTunes password prompt.&#160; Since the UIAlertView control has already been laid out, moving those controls around within the frame is not as straight forward a task as it may seem.&#160; Before we tackle that we will explore a simpler method that overlays the text field directly on top of the message label.&#160; You sacrifice being able to display an additional message to the user, but the end result looks professional and is very easy to implement.&#160; This will also be the basis for getting the control to have the same look and feel as the iTunes password prompt, so it is important to understand this prior to attempting to move the controls around.</p>
<p>The key to overlaying the text field on top of the message label is setting the bounding rectangle for the UITextField.&#160; The bounding rectangle is where the text field draws the box in which a user enters text.&#160; For our purposes, the rectangle needs to be drawn in between the title label and the buttons.&#160; It is important to make sure that it covers the area where the message label is drawn.&#160; Thanks to the work of others we know that if we start drawing the text field at the x,y offset of 12,45 that the text field will hide the message label.</p>
<p>The code to overlay the text field is as follows:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5cf6cd71-f852-4415-a2b2-654336f59dbe" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">void</span><span style="color: #000000;"> PromptForName(HandlerToUse handlerType)
{
    UITextField tf </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> UITextField (</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> System.Drawing.RectangleF (12f, 45f, 260f, 25f));
    tf.BackgroundColor </span><span style="color: #000000;">=</span><span style="color: #000000;"> UIColor.White;
    tf.UserInteractionEnabled </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
    tf.AutocorrectionType </span><span style="color: #000000;">=</span><span style="color: #000000;"> UITextAutocorrectionType.No;
    tf.AutocapitalizationType </span><span style="color: #000000;">=</span><span style="color: #000000;"> UITextAutocapitalizationType.None;
    tf.ReturnKeyType </span><span style="color: #000000;">=</span><span style="color: #000000;"> UIReturnKeyType.Done;
    tf.SecureTextEntry </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">; 

    UIAlertView myAlertView </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> UIAlertView
    {
        Title </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Please enter your name</span><span style="color: #800000;">"</span><span style="color: #000000;">,
        Message </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">this line is hidden</span><span style="color: #800000;">"</span><span style="color: #000000;">
    };

    myAlertView.AddButton(</span><span style="color: #800000;">"</span><span style="color: #800000;">Cancel</span><span style="color: #800000;">"</span><span style="color: #000000;">);
    myAlertView.AddButton(</span><span style="color: #800000;">"</span><span style="color: #800000;">Ok</span><span style="color: #800000;">"</span><span style="color: #000000;">);
    myAlertView.AddSubview(tf);
    </span><span style="color: #008000;">//</span><span style="color: #008000;"> More Setup Goes Here</span><span style="color: #008000;">
</span><span style="color: #000000;">    myAlertView.Show ();
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>The method starts by instantiating a UITextField control with a bounding rectangle passed via its constructor.&#160; The rectangle itself is constructed with four parameters via its constructor: the first two parameters set the x and y offset from the origin point of the control, and the last two parameters set the size of the drawing area.&#160; After the initial construction of the UITextField, a few additional properties are set to customize the display.&#160; </p>
<p>Among the properties set is the <em>SecureTextEntry</em>.&#160; Setting this property to true will make the text field act like a password field and hide all the characters that you’ve entered.&#160; Once the text field has been created and initialized, we move on to creating a UIAlertView.&#160; Via object initialization, the <em>Title</em> and <em>Message</em> properties are set with some text.&#160; Finally, two buttons are created, and the text field is added as a sub-view to the UIAlertView.&#160; Calling the show on the UIAlertView causes the alert to pop up.&#160; Below you can see the rendered control.</p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/TextField_As_Subview_UIAlertView.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="TextField_As_Subview_UIAlertView" border="0" alt="TextField_As_Subview_UIAlertView" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/TextField_As_Subview_UIAlertView_thumb.png" width="244" height="122" /></a></p>
<p>So now that we have the basic control setup, we can tweak it so that the text field and the message label can both be displayed.</p>
<p>If you recall our custom UIAlertView control is currently composed of two UILabels, two UIButtons and a UITextField that we added.&#160; The UILabels are derived from UIView and is not a subclass of UIControl; whereas, the UIButton and the UITextField are both derived from UIControls.&#160; Since we want to position the UITextField beneath the labels, we can use this knowledge to selectively shift only the UIControls in the view down leaving the title and message labels in place.</p>
<p>To accomplish this task the following steps need to be performed:</p>
<p>1) The control height needs to be increased to make space for the text field and provide additional space to move the UIControls.&#160; This is done by setting the frame to a larger size.&#160; The frame will be increased by the height of the text field plus a buffer, so the control has space between it and the others. </p>
<p>This is what the frame looks like after being enlarged: </p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/FrameEnlarged_CustomUIAlertView.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="FrameEnlarged_CustomUIAlertView" border="0" alt="FrameEnlarged_CustomUIAlertView" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/FrameEnlarged_CustomUIAlertView_thumb.png" width="244" height="153" /></a>&#160;
<p>
  <br />2) Once the frame has been enlarged, we’ll loop through the sub-views looking for UIControls and adjust only those types down by the same text field plus buffer offset </p>
<p>Here is what the control looks like after each UIControl is found during the iteration through the sub-views. </p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/FirstUIControlShifted_CancelButton.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="FirstUIControlShifted_CancelButton" border="0" alt="FirstUIControlShifted_CancelButton" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/FirstUIControlShifted_CancelButton_thumb.png" width="244" height="153" /></a><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/SecondUIControlShifted_OkButton.png"><br />
    <br /><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="SecondUIControlShifted_OkButton" border="0" alt="SecondUIControlShifted_OkButton" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/SecondUIControlShifted_OkButton_thumb.png" width="244" height="153" /></a> </p>
<p><a href="http://blog.kevfoo.com/wp-content/uploads/2009/11/FinalUIControlShifted_TextField.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="FinalUIControlShifted_TextField" border="0" alt="FinalUIControlShifted_TextField" src="http://blog.kevfoo.com/wp-content/uploads/2009/11/FinalUIControlShifted_TextField_thumb.png" width="244" height="154" /></a></p>
<p>Here is the code that does the control adjustment:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ad10f1fa-b7f3-477a-8553-a24998ed586e" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> TextFieldAlertView : UIAlertView
{
    </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> UITextField _tf;

    </span><span style="color: #008000;">//</span><span style="color: #008000;"> ... </span><span style="color: #008000;">
</span><span style="color: #000000;">
    </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> AdjustControlSize()
    {
        </span><span style="color: #0000FF;">float</span><span style="color: #000000;"> tfExtH </span><span style="color: #000000;">=</span><span style="color: #000000;"> _tf.Frame.Size.Height </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">16.0f</span><span style="color: #000000;">;

        var frame </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> RectangleF(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Frame.X,
                                    </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Frame.Y </span><span style="color: #000000;">-</span><span style="color: #000000;"> tfExtH</span><span style="color: #000000;">/</span><span style="color: #800080;">2</span><span style="color: #000000;">,
                                    </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Frame.Size.Width,
                                    </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Frame.Size.Height </span><span style="color: #000000;">+</span><span style="color: #000000;"> tfExtH);

        </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Frame </span><span style="color: #000000;">=</span><span style="color: #000000;"> frame;

        </span><span style="color: #0000FF;">foreach</span><span style="color: #000000;">(var view </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Subviews)
        {
            </span><span style="color: #0000FF;">if</span><span style="color: #000000;">(view </span><span style="color: #0000FF;">is</span><span style="color: #000000;"> UIControl)
            {
                view.Frame </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> RectangleF(view.Frame.X,
                                            view.Frame.Y </span><span style="color: #000000;">+</span><span style="color: #000000;"> tfExtH,
                                            view.Frame.Size.Width,
                                            view.Frame.Size.Height);
            }
        }
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>So now that the desired look and feel of the control has been established, it is time to wire up the control.&#160; There are a couple options for handling events generated by the control: one is more in line with how Cocoa handles events, and another that is similar to how .Net works.&#160; </p>
<p>The Cocoa way to wire up delegates involves subclassing a special delegate class associated to the control and selectively overriding the methods for the actions you want to customize.&#160; In the case of the UIAlertView control, that delegate class is a <a href="http://www.go-mono.com/docs/index.aspx?link=C%3AMonoTouch.UIKit.UIAlertViewDelegate">UIAlertViewDelegate</a>.&#160; The delegate class includes overridable methods like <em>Clicked</em> where you can define the actions to take when a button on the control is clicked or where you can extend behaviors by overriding methods like <em>Preseneted</em> which is called after the control has been displayed to the user.</p>
<p>The .Net way to wire up events is to provide specific delegates for specific events.&#160; To make interacting with the Cocoa Touch controls easier, Monotouch provides public events for each one of the methods that can be overridden in the UIAlertViewDelegate class.&#160; Having the individual public events makes wiring up controls more intuitive for the .Net developer, but it is good to know about the Cocoa-style approach especially when looking at Objective-C examples and/or ADC docs.&#160; I have examples of wiring up the control via both methods in the example source.</p>
<p>The last topic I’d like to cover briefly is how I encapsulated the customization of control by subclassing UIAlertView.&#160; The key to getting the control to look right is to override the LayoutSubviews method and build out the text field, add it to the UIAlertView and shift the controls around there.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8d5d040c-523d-4749-9da5-93a758fb8e3a" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> LayoutSubviews ()
{
    </span><span style="color: #008000;">//</span><span style="color: #008000;"> layout the stock UIAlertView</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.LayoutSubviews ();

    </span><span style="color: #008000;">//</span><span style="color: #008000;"> build out the text field</span><span style="color: #008000;">
</span><span style="color: #000000;">    _tf </span><span style="color: #000000;">=</span><span style="color: #000000;"> ComposeTextFieldControl(_secureTextEntry);

    </span><span style="color: #008000;">//</span><span style="color: #008000;"> add the text field to the UIAlertView</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.AddSubview(_tf);

    </span><span style="color: #008000;">//</span><span style="color: #008000;"> shift the UIControls to fit the text field</span><span style="color: #008000;">
</span><span style="color: #000000;">    AdjustControlSize();
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>I’ve added some more customizations to my subclassed UIAlertView control that allows you to enable the text field security via a constructor parameter and a tweak to the control’s Transform property to shift the control up so it isn’t hidden by the keyboard.&#160; You can see those changes and the entire working example <a href="http://github.com/kevinmcmahon/CustomUITextFieldAlertView">here on github</a>.</p>
<p>Enjoy.</p>
<p>Links to some of the resources used: </p>
<ul>
<li><a href="http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html">Alert View with Prompt (iPhone Development Blog)</a> </li>
<li><a href="http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html">Displaying a password or text entry prompt on the iPhone (Junecode Blog)</a> </li>
<li><a href="http://codesofa.com/blog/archive/2009/07/15/look-uialertview-is-dating-uitableview.html">Look UIAlertView is Dating UITableView (codesofa)</a> </li>
<li><a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html">iPhone Dev Center: UIAlertViewDelegate Protocol Reference (Apple, <em>login required</em>)</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.kevfoo.com/index.php/2009/11/monotouch-uialertview-uitextfield-crazy-delicious/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fun with Monotouch and Multi-Level Table Views without Interface Builder</title>
		<link>http://blog.kevfoo.com/index.php/2009/11/fun-with-monotouch-and-multi-level-table-views-without-interface-builder/</link>
		<comments>http://blog.kevfoo.com/index.php/2009/11/fun-with-monotouch-and-multi-level-table-views-without-interface-builder/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 21:36:00 +0000</pubDate>
		<dc:creator>Kevin McMahon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[UITableViewController]]></category>
		<category><![CDATA[cocoa touch]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[Adc]]></category>
		<category><![CDATA[App Development]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Craig Dunn]]></category>
		<category><![CDATA[Data Visualization]]></category>
		<category><![CDATA[Detail View]]></category>
		<category><![CDATA[Example Tutorials]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[Mac Mini]]></category>
		<category><![CDATA[Monospace]]></category>
		<category><![CDATA[Navigation Button]]></category>
		<category><![CDATA[New Mac]]></category>
		<category><![CDATA[Pdc]]></category>
		<category><![CDATA[Perfect Time]]></category>
		<category><![CDATA[Programming Guide]]></category>
		<category><![CDATA[Roget]]></category>
		<category><![CDATA[Rss Reader]]></category>
		<category><![CDATA[Thesaurus]]></category>
		<category><![CDATA[Ugly Code]]></category>

		<guid isPermaLink="false">http://blog.kevfoo.com/index.php/2009/11/fun-with-monotouch-and-multi-level-table-views-without-interface-builder/</guid>
		<description><![CDATA[With the recent release of&#160; Monotouch, which enabled development for the iPhone/iPod Touch platform using C# and .Net, it seemed like the perfect time to take a swing at mobile app development.&#160; The strong appeal of being able to leverage my C# and .Net experience while scratching an itch that I have had for a [...]]]></description>
			<content:encoded><![CDATA[<p>With the recent release of&#160; <a href="http://monotouch.net/">Monotouch</a>, which enabled development for the iPhone/iPod Touch platform using C# and .Net, it seemed like the perfect time to take a swing at mobile app development.&#160; The strong appeal of being able to leverage my C# and .Net experience while scratching an itch that I have had for a few apps was more than enough to entice me to order a brand new <a href="http://www.amazon.com/gp/product/B002QQ8CC4?ie=UTF8&amp;tag=kev02-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B002QQ8CC4">Mac mini</a><img style="border-bottom-style: none !important; border-right-style: none !important; margin: 0px; border-top-style: none !important; border-left-style: none !important" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=kev02-20&amp;l=as2&amp;o=1&amp;a=B002QQ8CC4" width="1" height="1" /> and start learning the Cocoa framework.</p>
<p>My pet app project requires some pretty basic multi-level tabular data visualization, so that was the first thing I attempted to tackle.&#160; I started my learning endeavor by reading the <a href="http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html">view controller programming guide</a> from <a href="http://developer.apple.com">Apple’s ADC</a> and working through a few of the <a href="http://monotouch.net/Tutorials">tutorials</a> listed on the Monotouch site.&#160; One of the example tutorials listed was for <a href="http://www.alexyork.net/blog/post/UINavigationController-with-MonoTouch-Building-a-simple-RSS-reader-Part-1.aspx">a basic RSS reader</a>.&#160; Armed with his guide, I got up and running with a basic table view allowed me to drill down one level deep and return to the root via navigation button.&#160; This was a great introduction and the easy to follow steps combined with the screenshots certainly hit the mark; however, this was not quite the layout I was looking for.</p>
<p>The data that I wanted to display calls for more than just a list-view-to-detail-view relationship that the RSS reader implemented.&#160; As a beginner trying to figure out how to wire up my custom table controllers to each other and the navigation controller all via Interface Builder resulted in a lot of thrashing and a lot of ugly code.&#160; I eventually was able to roughly approximate the behavior I wanted, but it was pretty obvious to me there had to be a better way.</p>
<p>I set out to see if I could find more Monotouch examples to see if I could pick up some tips and stumbled across <a href="http://conceptdev.blogspot.com/">Craig Dunn’s blog</a>.&#160; Craig not only put together apps for the Monospace and PDC conferences (and graciously provided the source) but also posted a <a href="http://conceptdev.blogspot.com/2009/10/monotouch-rogets-1911-thesaurus.html">Roget’s Thesaurus</a> app that was just what I was looking for.&#160; It was a simple app, but it had all the elements in play that I was looking for and an <a href="http://3.bp.blogspot.com/_Ba76y6K7kvs/Su66_wEzO3I/AAAAAAAABIQ/9MzCAwYQ-HQ/s1600-h/RogetPlacemat.png">incredible diagram</a> that tied it all together.</p>
<p>One of the key tips and tricks I picked up from Craig’s code was how easy it was to cut out the Interface Builder from the process.&#160; I also generally tend to avoid using the designer whenever possible in Visual Studio but here it was a key factor in my understand.&#160; This isn’t to say that I’d never use the Interface Builder again or that it doesn’t have its uses because it does but there was <em>too much</em> magic going on in how Monotouch links up the XIBs to their backing C# classes.&#160; It wasn’t until I started explicitly creating views and view controllers instead of trying to wire them up after the fact did I start to understand how things were supposed to interact.</p>
<p>To implement a custom <strong>UITableViewController</strong> you need to set two properties with custom classes and override a method which is invoked by the framework when the view controller is loaded.&#160; You’ll need to set the TableDelegate and DataSource properties on the controller with your own implementations of <strong>UITableViewDelegate </strong>and&#160; <strong>UITableViewDataSource</strong>.&#160; The implementation of the table delegate allows you to customize how the table will respond to certain events and the data source implementation provides not only the data the table uses but also how that data is to be displayed within the table.&#160; Typically the ViewDidLoad method is overriden to perform the view setup work needed during initialization of the view controller.&#160; Within the method the TableDelegate and DataSource properties can be set.</p>
<p>Example setting the TableDelegate and DataSource via the ViewDidLoad method:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:18bc747e-a016-49a3-889d-2df3afb9f710" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">namespace</span><span style="color: #000000;"> MultiLevelTableView
{
    [MonoTouch.Foundation.Register(</span><span style="color: #800000;">"</span><span style="color: #800000;">RootViewController</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">partial</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> RootViewController : UITableViewController
    {
        </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> DataSource : UITableViewDataSource { </span><span style="color: #008000;">/*</span><span style="color: #008000;"> Impl Here </span><span style="color: #008000;">*/</span><span style="color: #000000;"> }

        </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> TableDelegate : UITableViewDelegate { </span><span style="color: #008000;">/*</span><span style="color: #008000;"> Impl Here </span><span style="color: #008000;">*/</span><span style="color: #000000;"> }

        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> ViewDidLoad ()
        {
            </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.ViewDidLoad ();

            TableView.Delegate </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> TableDelegate (</span><span style="color: #0000FF;">this</span><span style="color: #000000;">);
            TableView.DataSource </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> DataSource (</span><span style="color: #0000FF;">this</span><span style="color: #000000;">);
        }
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>Example setting the properties during <strong>UITableView</strong> construction:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ac5c342a-bdfc-49a2-89b8-5da3f272da4f" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">namespace</span><span style="color: #000000;"> MultiLevelTableView
{
    [MonoTouch.Foundation.Register(</span><span style="color: #800000;">"</span><span style="color: #800000;">RootViewController</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">partial</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> RootViewController : UITableViewController
    {
        UITableView tableView;

        </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> DataSource : UITableViewDataSource { </span><span style="color: #008000;">/*</span><span style="color: #008000;"> Impl Here </span><span style="color: #008000;">*/</span><span style="color: #000000;"> }

        </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> TableDelegate : UITableViewDelegate { </span><span style="color: #008000;">/*</span><span style="color: #008000;"> Impl Here </span><span style="color: #008000;">*/</span><span style="color: #000000;"> }

        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> ViewDidLoad ()
        {
            </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.ViewDidLoad ();

            tableView </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> UITableView()
            {
                Delegate </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> TableViewDelegate(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">),
                DataSource </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> TableViewDataSource(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">),
            };

            </span><span style="color: #008000;">//</span><span style="color: #008000;">You can set more properties here like size and
            </span><span style="color: #008000;">//</span><span style="color: #008000;">location in the frame etc.</span><span style="color: #008000;">
</span><span style="color: #000000;">
            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.View.AddSubview(tableView);
        }
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>The meat of the table view controller falls in the implementations of the DataSource and TableDelegate.</p>
<p>A basic DataSource setup involves overriding two methods used by parent controller.&#160; The RowsInSection method tells how many rows need to be displayed in the table and the GetCell method returns a cell view which was customized for display by setting the text and display properties.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c5c83938-3d1d-47b9-8e66-91d91b0673c8" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">class</span><span style="color: #000000;"> DataSource : UITableViewDataSource
{
    </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> NSString kCellIdentifier </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> NSString (</span><span style="color: #800000;">"</span><span style="color: #800000;">MyIdentifier</span><span style="color: #800000;">"</span><span style="color: #000000;">);
    RootViewController tvc;

    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> DataSource (RootViewController tvc)
    {
        </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.tvc </span><span style="color: #000000;">=</span><span style="color: #000000;"> tvc;
    }

    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> RowsInSection (UITableView tableView, </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> section)
    {
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> tvc.RootData.Count;
    }

    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
    {
        var cell </span><span style="color: #000000;">=</span><span style="color: #000000;"> tableView.DequeueReusableCell (kCellIdentifier);

        </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (cell </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
        {
            cell </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> UITableViewCell (UITableViewCellStyle.Default, kCellIdentifier);
        }

        cell.TextLabel.Text </span><span style="color: #000000;">=</span><span style="color: #000000;"> tvc.RootData.ElementAt(indexPath.Row);
        cell.Accessory </span><span style="color: #000000;">=</span><span style="color: #000000;"> UITableViewCellAccessory.DetailDisclosureButton;
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> cell;
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>The TableDelegate is where the behavior of the table to various events is defined.&#160; It is here in which we load up the next view to display when a user clicks on a cell.&#160;&#160; A basic implementation of a table view delegate involves overriding the RowSelected method with instructions on what to do with the row now that it has been selected.&#160; If the node selected happened to be a leaf node for example we might load up the detail’s view to display the nodes properties or if the node was the parent of more child nodes we would load another list view to continue to drill down into the data.&#160; In our case we want to drill down to the next layer of data which is managed by the SubGroupViewController.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:598700d1-088c-449d-9ed0-f36c3bab6d9e" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">class</span><span style="color: #000000;"> TableDelegate : UITableViewDelegate
{
    RootViewController tvc;
    SubGroupViewController sgvc;

    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> TableDelegate (RootViewController tvc)
    {
        </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.tvc </span><span style="color: #000000;">=</span><span style="color: #000000;"> tvc;
    }

    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> RowSelected (UITableView tableView, NSIndexPath indexPath)
    {
        </span><span style="color: #008000;">//</span><span style="color: #008000;"> get info from selected row</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #0000FF;">string</span><span style="color: #000000;"> selectedGroup </span><span style="color: #000000;">=</span><span style="color: #000000;"> tvc.RootData.ElementAt(indexPath.Row);

        </span><span style="color: #008000;">//</span><span style="color: #008000;"> load up new controller to display</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #0000FF;">if</span><span style="color: #000000;">(sgvc </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
            sgvc </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SubGroupViewController(selectedGroup);

        </span><span style="color: #008000;">//</span><span style="color: #008000;"> push the controller on the navigation stack</span><span style="color: #008000;">
</span><span style="color: #000000;">        tvc.NavigationController.PushViewController(sgvc, </span><span style="color: #0000FF;">true</span><span style="color: #000000;">);
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>The hang up for me with using Interface Builder to try and get the multi-level table views wired together was mostly due to not being familiar with the objects I was dealing with and not understanding what properties are needed to be initialized so the framework can display them correctly.&#160; Approaching the problem via the Interface Builder created a lot of noise that made seeing what was really needed to wire these table view controllers with the navigation controller difficult.&#160; In this case the the pre-packaged templates and generic layouts provided by Monotouch and Interface Builder were more of a hindrance than help but that is to be expected while learning a new technology.</p>
<p>I’ve packaged up my <a href="http://github.com/kevinmcmahon/MultiLevelTableView">implementation of a multi-level table view</a> app and put it on github.&#160; If anyone is looking for straight-forward, simple example of nesting table views hopefully this will help.</p>
<p>I also recommend checking out the following links which helped me immensely:</p>
<ul>
<li><a href="http://www.alexyork.net/blog/category/MonoTouch.aspx">Alex York&#8217;s Monotouch posts including the RSS reader</a>&#160; </li>
<li><a href="http://sabonrai.wordpress.com/2009/08/28/monotouch-sample-code-uitableview/">Sabon Rai&#8217;s Sample Code for UITableView</a> </li>
<li><a href="http://conceptdev.blogspot.com/">Craig Dunn’s Blog</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.kevfoo.com/index.php/2009/11/fun-with-monotouch-and-multi-level-table-views-without-interface-builder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
