<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hans Pinckaers</title>
	<atom:link href="http://www.hanspinckaers.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hanspinckaers.com</link>
	<description></description>
	<lastBuildDate>Mon, 12 Dec 2011 10:26:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>KVO+Blocks</title>
		<link>http://www.hanspinckaers.com/kvoblocks</link>
		<comments>http://www.hanspinckaers.com/kvoblocks#comments</comments>
		<pubDate>Wed, 14 Jul 2010 11:38:36 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=360</guid>
		<description><![CDATA[Just found out this little NSObject category. It&#8217;s awesome. A must #include in your project. &#8220;To get observation notices, you have to override a lengthy selector (observeValueForKeyPath:ofObject:change:context:), provide a static context pointer, and essentially implement a big switch statement on the key path. That’s unwieldy, but I think it also makes for unmaintainable code: the [...]]]></description>
			<content:encoded><![CDATA[<p>Just found out this little NSObject category. It&#8217;s awesome. A must #include in your project.</p>
<p><span id="more-360"></span></p>
<blockquote><p>&#8220;To get observation notices, you have to override a lengthy selector (observeValueForKeyPath:ofObject:change:context:), provide a static context pointer, and essentially implement a big switch statement on the key path.</p>
<p>That’s unwieldy, but I think it also makes for unmaintainable code: the callbacks end up thrown in the same method, and they’re separated from the observer registration.&#8221;</p></blockquote>
<p>~ <a href="http://blog.andymatuschak.org/post/156229939/kvo-blocks-block-callbacks-for-cocoa-observers">KVO+Blocks: Block Callbacks for Cocoa Observers</a></p>
<p>Since iOS 4 support blocks, it&#8217;s possible to use this for iPhone projects too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/kvoblocks/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multi-line/Autoresizing UITextView similar to SMS-app</title>
		<link>http://www.hanspinckaers.com/multi-line-uitextview-similar-to-sms</link>
		<comments>http://www.hanspinckaers.com/multi-line-uitextview-similar-to-sms#comments</comments>
		<pubDate>Thu, 01 Jul 2010 12:19:40 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=298</guid>
		<description><![CDATA[I&#8217;ve been tinkering around the last days, creating a multi-line UITextView. I wanted a SMS-app like experience and needed a growing (and shrinking) textView. I tried using three20&#8242;s TTTextEditor, but it disables the bounces of the scroll (which is ugly) and has this big white margin on the bottom when you scroll down manually. So [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tinkering around the last days, creating a multi-line UITextView. I wanted a SMS-app like experience and needed a growing (and shrinking) textView. I tried using three20&#8242;s TTTextEditor, but it disables the bounces of the scroll (which is ugly) and has this big white margin on the bottom when you scroll down manually. So I needed a UITextView which grows/shrinks with the text always on the bottom and a bouncing scroll. Well, I wouldn&#8217;t be blogging this if I wouldn&#8217;t have been succesful.<br />
<span id="more-298"></span>
</p>
<h3>Growing and Shrinking</h3>
<p>I started with the code of Brett Schumann (<a href="http://brettschumann.com/blog/2010/01/15/iphone-multiline-textbox-for-sms-style-chat">iPhone Multiline Textbox for SMS style chat</a>). Brett calculates the new height when UITextViewTextDidChangeNotification is posted. He determines the needed height by using sizeWithFont:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGSize newSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>textView.text
            sizeWithFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">14</span><span style="color: #002200;">&#93;</span>
            constrainedToSize<span style="color: #002200;">:</span>CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">222</span>,<span style="color: #2400d9;">9999</span><span style="color: #002200;">&#41;</span>
            lineBreakMode<span style="color: #002200;">:</span>UILineBreakModeWordWrap<span style="color: #002200;">&#93;</span>;</pre></div></div>

</p>
<p>I find this rather inconsistent with other typefaces and sized, because of the inset/padding of the UITextView.</p>
<p>I ended with a much simpler approach, using the textViewDidChange: delegate method. This method is called after inserting the typed character. Determining the height is than as easy as: <strong>textView.contentSize.height</strong> (UITextView extends UIScrollView)</p>
<p>Determining the height of, for example, one line is done by a hidden UITextView, this is needed for the properties of minNumberOfLines and maxNumberOfLines.</p>
<h3>Removing the bottom margin</h3>
<p>The first problem that comes about when using a UITextView with one line is that the UITextView scrolls up when focused. With googling you can find the answer for the solution:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">textView.contentInset <span style="color: #002200;">=</span> UIEdgeInsetsZero;</pre></div></div>

</p>
<p>Some people say that the “word-tip” or correction bubble will be cut by the bounds of the UITextview, but I couldn&#8217;t reproduce that.</p>
<p>Removing the bottom margin took quite a long time. After a few days of research I found out that UITextView is setting the contentInset on unpredictable times. I tried setting it in several delegate methods but ended up in subclassing UITextView and overriding the method. It seems that this works perfectly.</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setContentInset<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEdgeInsets<span style="color: #002200;">&#41;</span>s
<span style="color: #002200;">&#123;</span>
	UIEdgeInsets insets <span style="color: #002200;">=</span> s;
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>s.bottom&gt;<span style="color: #2400d9;">8</span><span style="color: #002200;">&#41;</span> insets.bottom <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	insets.top <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>super setContentInset<span style="color: #002200;">:</span>insets<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

</p>
<p>Sometimes you want a inset on the bottom when you&#8217;re typing and wraps to the next line. But when the user is going to scroll manually you need to set the inset to 0. The solution is overriding setContentOffset:.</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setContentOffset<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>s
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self.tracking || self.decelerating<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">//initiated by user...</span>
		self.contentInset <span style="color: #002200;">=</span> UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		<span style="color: #a61390;">float</span> bottomOffset <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>self.contentSize.height <span style="color: #002200;">-</span> self.frame.size.height <span style="color: #002200;">+</span> self.contentInset.bottom<span style="color: #002200;">&#41;</span>;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>s.y &lt; bottomOffset <span style="color: #002200;">&amp;&amp;</span> self.scrollEnabled<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			self.contentInset <span style="color: #002200;">=</span> UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">8</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//maybe use scrollRangeToVisible?</span>
		<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>super setContentOffset<span style="color: #002200;">:</span>s<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

</p>
<h3>Delegate and UITextView properties</h3>
<p>The class uses a internal UITextView, but you can set nearly all properties on a class instance, the will be applied on the internal UITextView. All the UITextView delegate methods are also possible to use.</p>
<p>I also included 2 delegate methods for determining when a grow/shrink starts. willChangeHeight is called within the animation block, so every change you make there on a view gets animated.</p>
<h3>The Delegate methods</h3>
<p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>growingTextViewShouldBeginEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>growingTextViewShouldEndEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>growingTextViewDidBeginEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>growingTextViewDidEndEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>growingTextView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView shouldChangeTextInRange<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSRange</span><span style="color: #002200;">&#41;</span>range replacementText<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>text;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>growingTextViewDidChange<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;
&nbsp;
<span style="color: #11740a; font-style: italic;">//called WITHIN animation block!</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>growingTextView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView willChangeHeight<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>height;
&nbsp;
<span style="color: #11740a; font-style: italic;">//called after animation</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>growingTextView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView didChangeHeight<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>height;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>growingTextViewDidChangeSelection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>growingTextViewShouldReturn<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>HPGrowingTextView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>growingTextView;</pre></div></div>

</p>
<h3>The included properties</h3>
<p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> maxNumberOfLines;
<span style="color: #a61390;">int</span> minNumberOfLines;
&nbsp;
<span style="color: #a61390;">BOOL</span> animateHeightChange; <span style="color: #11740a; font-style: italic;">//default is YES</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//UITextView properties</span>
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>text;
UIFont <span style="color: #002200;">*</span>font;
UIColor <span style="color: #002200;">*</span>textColor;
UITextAlignment textAlignment;
<span style="color: #a61390;">NSRange</span> selectedRange;
<span style="color: #a61390;">BOOL</span> editable;
UIDataDetectorTypes dataDetectorTypes;
UIReturnKeyType returnKeyType;</pre></div></div>

</p>
<p>You can read/write the properties on a class instance. When you need to set a specific property that is not listed here, you can set it directly on the internalTextView. Be careful though; the HPGrowingTextView needs to stay the delegate of the internalTextView!</p>
<h3>Download</h3>
<p><a href="https://github.com/HansPinckaers/GrowingTextView">GrowingTextView</a></p>
<p>Update: Added fixes suggested in the comments.</p>
<p>License: <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a></p>
<p>It&#8217;s a zip file, with the class and an example included.</p>
<p><strong>Please comment if you use it or found any problems.</strong></p>
<p>Too lazy to build the sample project or just want to see if this is what you are looking for? Here is a movie showing the HPGrowingTextView;</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="480" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=13003070&#038;server=vimeo.com&#038;show_title=1&#038;show_byline=1&#038;show_portrait=0&#038;color=&#038;fullscreen=1" /><embed type="application/x-shockwave-flash" width="320" height="480" src="http://vimeo.com/moogaloop.swf?clip_id=13003070&#038;server=vimeo.com&#038;show_title=1&#038;show_byline=1&#038;show_portrait=0&#038;color=&#038;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/multi-line-uitextview-similar-to-sms/feed</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Routes/Lines on a MKMapView (as a MKAnnotationView) – Part 2.5</title>
		<link>http://www.hanspinckaers.com/routes-on-a-mkmapview-as-an-mkannotationview-%e2%80%93-part-2-5</link>
		<comments>http://www.hanspinckaers.com/routes-on-a-mkmapview-as-an-mkannotationview-%e2%80%93-part-2-5#comments</comments>
		<pubDate>Thu, 25 Mar 2010 20:55:06 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=263</guid>
		<description><![CDATA[Download available after the jump. First, I should credit Craig for his example of drawing lines on a MKMapView (http://spitzkoff.com/craig/?p=108), that&#8217;s where you can find part 1 and part 2. This post is a teaser of what I am going to post later this month. It&#8217;s a improvement on his code and makes overlays on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Download available after the jump.</strong></p>
<p>First, I should credit Craig for his example of drawing lines on a MKMapView (<a href="http://spitzkoff.com/craig/?p=108">http://spitzkoff.com/craig/?p=108</a>), that&#8217;s where you can find part 1 and part 2. This post is a teaser of what I am going to post later this month. It&#8217;s a improvement on his code and makes overlays on a MKMapView possible without the need to hide it when zooming/panning around.<span id="more-263"></span></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="576" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=10440203&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="320" height="576" src="http://vimeo.com/moogaloop.swf?clip_id=10440203&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>The performance is pretty good. There is absolutely no lag on the iPhone 3GS, you will notice that panning/zooming around on the iPhone 3G is not that smooth as on the 3GS, but it&#8217;s acceptable.</p>
<p>I will publish it here on my blog when my app update is ready and Apple approved it. Will be in a month or so. If you actually found a way of doing this please let me now, I still looking for other ideas.</p>
<p>&#8211; </p>
<h3>Download</h3>
<p>I do not have a lot of time to write a big blogpost, so I&#8217;m just going to post the code, and maybe later write the explanation.</p>
<p><a href="http://hanspinckaers.com/mapLinesAndAnnotations.zip">Download project here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/routes-on-a-mkmapview-as-an-mkannotationview-%e2%80%93-part-2-5/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to create a UITableViewCell with &#8220;copy&#8221; ability</title>
		<link>http://www.hanspinckaers.com/how-to-create-a-uitableviewcell-with-copy-possibility</link>
		<comments>http://www.hanspinckaers.com/how-to-create-a-uitableviewcell-with-copy-possibility#comments</comments>
		<pubDate>Sun, 31 Jan 2010 21:37:48 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[uitableview]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=237</guid>
		<description><![CDATA[It&#8217;s possible to copy the content of a UITableViewCell in the Contacts app of Apple. When you tap and hold you will see a small menu with &#8220;Copy&#8221;. I needed this functionality myself, so I subclassed the class. You are free to use this in any application, but it would be awesome if you mention [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s possible to copy the content of a UITableViewCell in the Contacts app of Apple. When you tap and hold you will see a small menu with &#8220;Copy&#8221;. I needed this functionality myself, so I subclassed the class. You are free to use this in any application, but it would be awesome if you mention me in the credits of your App. <span id="more-237"></span></p>
<h3>It&#8217;s easy to use</h3>
<ol>
<li>Copy the files in your project.</li>
<li>Use this code to create a cell:

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>HPCopyTableViewCell alloc<span style="color: #002200;">&#93;</span> 
			initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleValue2 
		      reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h3>Download</h3>
<p><a href="http://www.hanspinckaers.com/HPCopyTableViewCell.zip">HPCopyTableViewCell.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/how-to-create-a-uitableviewcell-with-copy-possibility/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Custom action on Back Button UINavigationController</title>
		<link>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller</link>
		<comments>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller#comments</comments>
		<pubDate>Fri, 27 Nov 2009 22:17:05 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[uinavigationcontroller]]></category>

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

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

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

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

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

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

]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>High performance rounded corner UITableView</title>
		<link>http://www.hanspinckaers.com/high-performance-rounded-corner-uitableview</link>
		<comments>http://www.hanspinckaers.com/high-performance-rounded-corner-uitableview#comments</comments>
		<pubDate>Sat, 24 Oct 2009 07:51:55 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[uitableview]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=143</guid>
		<description><![CDATA[The problem with the previous example was that I was using a second UIScrollView to scroll the UITableView and not the UITableView itself, which is a subclass of UIScrollView and highly optimized for scrolling. Here is a solution. The advantage of this one is that it is fast, but it&#8217;s not that easy and straightforward. [...]]]></description>
			<content:encoded><![CDATA[<p>The problem with the previous example was that I was using a second UIScrollView to scroll the UITableView and not the UITableView itself, which is a subclass of UIScrollView and highly optimized for scrolling.</p>
<p>Here is a solution. The advantage of this one is that it is fast, but it&#8217;s not that easy and straightforward.<span id="more-143"></span><br />
There are three view related properties for the uitableviewcell:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, readonly, retain<span style="color: #002200;">&#41;</span> UIView <span style="color: #002200;">*</span>contentView
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> UIView <span style="color: #002200;">*</span>backgroundView
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> UIView <span style="color: #002200;">*</span>selectedBackgroundView</pre></div></div>

<p>The backgroundView of the first and last UITableCell will be changed so that they have rounded corners at the proper place.</p>
<p>The selectedBackgroundview will be changed so that the blue selection of the first and last table cell will be corrected with the rounded corners of the backgroundView.</p>
<p>The gradient is drawn with Core Graphics. So you also learn with this project how to draw a gradient.</p>
<p>The only negative point of this technique is that I needed to make the separatorColor &#8220;clearColor&#8221;.</p>
<h3>Download the project</h3>
<p><a href="http://hanspinckaers.com/UIRoundedCornerTableView.zip">Here</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/high-performance-rounded-corner-uitableview/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Reproducing a tableView like in Stocks/Spotlight/Weather</title>
		<link>http://www.hanspinckaers.com/reproducing-a-tableview-like-in-stocks-spotlight-weather</link>
		<comments>http://www.hanspinckaers.com/reproducing-a-tableview-like-in-stocks-spotlight-weather#comments</comments>
		<pubDate>Wed, 21 Oct 2009 12:00:40 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[uitableview]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=125</guid>
		<description><![CDATA[This article is outdated. You can find the better optimized tableView here: http://www.hanspinckaers.com/high-performance-rounded-corner-uitableview To come straight out with it: the trick is view.layer.cornerRadius = 10; For this to work you need to include the QuartzCore into the class which you call that property: #import &#60;QuartzCore/QuartzCore.h&#62; I heard that this only works since OS 3.0. Haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This article is outdated. You can find the better optimized tableView here: <a href="http://www.hanspinckaers.com/high-performance-rounded-corner-uitableview">http://www.hanspinckaers.com/high-performance-rounded-corner-uitableview</a></strong></p>
<p>To come straight out with it: the trick is</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">view.layer.cornerRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">10</span>;</pre></div></div>

<p><span id="more-125"></span><br />
For this to work you need to include the QuartzCore into the class which you call that property:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;QuartzCore/QuartzCore.h&gt;</span></pre></div></div>

<p>I heard that this only works since OS 3.0. Haven&#8217;t checked it though.</p>
<p>This is the idea:<br />
Scrollview (rounded corners) -> TableView (rounded corners, scrolling disabled)</p>
<p><strong>Don&#8217;t use this with big tables because it will ruin the cache system of the table. I will post a solution and better method next week.</strong></p>
<p>This is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.view <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
scrollView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScrollView alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
scrollView.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">40</span>, <span style="color: #2400d9;">300</span>, <span style="color: #2400d9;">380</span><span style="color: #002200;">&#41;</span>;
scrollView.layer.cornerRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">15</span>;
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>scrollView<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>scrollView setShowsVerticalScrollIndicator<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
table <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>RoundedCornerTableViewController alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewStylePlain<span style="color: #002200;">&#93;</span>;
table.tableView.scrollEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
table.tableView.layer.cornerRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">15</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Should be set the same as</span>
<span style="color: #002200;">&#91;</span>scrollView setContentSize<span style="color: #002200;">:</span>CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">300</span>, <span style="color: #2400d9;">800</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
table.tableView.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">300</span>, <span style="color: #2400d9;">800</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#91;</span>scrollView addSubview<span style="color: #002200;">:</span>table.tableView<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h3>Download the sample project</h3>
<p><a href="http://hanspinckaers.com/RoundedCornerTableView.zip">Here.</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/reproducing-a-tableview-like-in-stocks-spotlight-weather/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multiple NSURLRequests with different cookies (asynchronous)</title>
		<link>http://www.hanspinckaers.com/multiple-nsurlrequests-with-different-cookies</link>
		<comments>http://www.hanspinckaers.com/multiple-nsurlrequests-with-different-cookies#comments</comments>
		<pubDate>Tue, 06 Oct 2009 11:12:49 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=71</guid>
		<description><![CDATA[I searched the whole internet for a solution but I didn&#8217;t find one. Yet I managed to get it to work. My problem was that I had several NSURLRequests who had to connect to one internet webservice, without an API, so I had to login behind the scenes with the provided login form from the [...]]]></description>
			<content:encoded><![CDATA[<p>I searched the whole internet for a solution but I didn&#8217;t find one. Yet I managed to get it to work. My problem was that I had several NSURLRequests who had to connect to one internet webservice, without an API, so I had to login behind the scenes with the provided login form from the normal website. This webpage uses cookies, but the NSURLRequest object on the iPhone uses a shared cookie storage. I wanted to use different accounts on one webservices with each their own cookies. <span id="more-71"></span></p>
<p>The solution was quite simple. You have to save the cookies after you get the response headers and you have to set them before doing the request. You also have to turn off the cookie handling via the shared cookie provider.</p>
<p>Here is the code for saving the cookies. self.currentCookies is an NSArray, you have to be sure that the delegate of the NSURLConnection is the same class.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection 
	didReceiveResponse<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLResponse</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>response
<span style="color: #002200;">&#123;</span>
    self.currentCookies <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSHTTPCookie</span> 
	cookiesWithResponseHeaderFields<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>response allHeaderFields<span style="color: #002200;">&#93;</span> 
	forURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Here is the code for using the saved cookies for a new request:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSMutableURLRequest</span> <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableURLRequest</span> alloc<span style="color: #002200;">&#93;</span> 
				initWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span>; 
&nbsp;
<span style="color: #002200;">&#91;</span>request setHTTPMethod<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;POST&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>request setHTTPShouldHandleCookies<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self.currentCookies <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>request setAllHTTPHeaderFields<span style="color: #002200;">:</span>
	<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSHTTPCookie</span> requestHeaderFieldsWithCookies<span style="color: #002200;">:</span>
		self.currentCookies<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span>connection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLConnection</span> alloc<span style="color: #002200;">&#93;</span> 
				initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/multiple-nsurlrequests-with-different-cookies/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multiple backgrounds with canvas drawing</title>
		<link>http://www.hanspinckaers.com/multiple-backgrounds-with-canvas-drawing</link>
		<comments>http://www.hanspinckaers.com/multiple-backgrounds-with-canvas-drawing#comments</comments>
		<pubDate>Thu, 02 Apr 2009 21:51:42 +0000</pubDate>
		<dc:creator>Hans Pinckaers</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.hanspinckaers.com/?p=10</guid>
		<description><![CDATA[The canvas HTML element was invented by Apple. It was created to dynamically create complex images for Widgets. There where a few complaints about the element, but despite of that it is included in the HTML 5.0 working draft. All modern browsers are compatible with the canvas-tag, beside of Internet Explorer, but Google created a [...]]]></description>
			<content:encoded><![CDATA[<p>The canvas HTML element was invented by Apple. It was created to dynamically create complex images for Widgets. There where a few complaints about the element, but despite of that it is included in the <em><a href="http://www.w3.org/TR/html5/the-canvas-element.html" target="_blank">HTML 5.0 working draft</a></em>. All modern browsers are compatible with the canvas-tag, beside of Internet Explorer, but Google created a superb piece of javascript that ported the canvas to IE. I created a little piece of javascript for drawing multiple backgrounds in a canvas element behind an <em>HTML</em> element. <span id="more-10"></span></p>
<h2>The syntax</h2>
<p>First the syntax to call the function. I use this code to draw the backgrounds behind the header in this site:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$mb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'info'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'url(http://hanspinckaers.com/img/mainBackgroundTop2.png) no-repeat 8px top'</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">'url(http://hanspinckaers.com/img/achtergrondHoofdartikel.jpg) no-repeat 8px bottom'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Examples</h2>
<ul>
<li>You can see a simple example with rounded corners <a href="http://hanspinckaers.com/mb/example/">here</a></li>
</ul>
<h2>Points of improvements</h2>
<ul>
<li>It’s buggy (report bugs please!)</li>
<li>Maybe convert it into a class</li>
<li>Speed (always a good one to improve)</li>
<li>Destination element must have an absolute or relative position declared in his css<strong></strong></li>
</ul>
<h2>Download</h2>
<p>Project homepage: <a href="http://github.com/HansPinckaers/mb.js/tree/master">at Github</a>. You can download the files from there.</p>
<h2>Using it</h2>
<p>You have to add these lines before you call the $mb funtion:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if IE]&gt;
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot; src=&quot;changed_excanvas_compressed.js&quot; mce_src=&quot;changed_excanvas_compressed.js&quot;&gt;&lt;/script&gt;
&lt;![endif]--&gt;
&lt;script src=&quot;mbmin.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:0--&gt;&lt;/script&gt;</pre></div></div>

<p>I modified googles <a href="http://code.google.com/p/explorercanvas/">excanvas</a> so it is smaller but can only be used to draw images.</p>
<p>If you have any questions, please ask in the comments! And please always keep progressive enhancement in mind, so set a normal replacement background in the css.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hanspinckaers.com/multiple-backgrounds-with-canvas-drawing/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

