<?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>Codec &#187; method</title>
	<atom:link href="http://www.trembl.org/codec/tag/method/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.trembl.org/codec</link>
	<description>A Personal Polylogic Code/Decode &#039;Zettelkasten&#039;</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:38:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Delaying Methods. And cancelling the delaying of methods</title>
		<link>http://www.trembl.org/codec/594/</link>
		<comments>http://www.trembl.org/codec/594/#comments</comments>
		<pubDate>Tue, 18 May 2010 09:11:36 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[cancel]]></category>
		<category><![CDATA[delay]]></category>
		<category><![CDATA[longest method name]]></category>
		<category><![CDATA[method]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/594/</guid>
		<description><![CDATA[Delaying a method should be by now fairly clear: &#91;self performSelector:@selector&#40;myMethod&#41; withObject:nil afterDelay:3&#93;; But what, if you need to cancel the delayed perform request? That&#8217;s the way to do it: &#91;NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector&#40;myMethod&#41; object:nil&#93;; &#8216;cancelPreviousPerformRequestsWithTarget&#8216; seems to be the current leader in the &#8216;Longest Objective C Method Name Competition&#8221; with 39 characters, not bad. Let [...]]]></description>
			<content:encoded><![CDATA[<p>Delaying a method should be by now fairly clear:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>self performSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>myMethod<span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> afterDelay<span style="color: #002200;">:</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>But what, if you need to cancel the delayed perform request? That&#8217;s the way to do it:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSObject</span> cancelPreviousPerformRequestsWithTarget<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>myMethod<span style="color: #002200;">&#41;</span> object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><em>&#8216;<strong>cancelPreviousPerformRequestsWithTarget</strong>&#8216; seems to be the current leader in the &#8216;Longest Objective C Method Name Competition&#8221; with 39 characters, not bad.</p>
<p>Let me <a href="http://www.twitter.com/trembl">know</a>, if you find any more contenders&#8230;<br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/594/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a custom delegate</title>
		<link>http://www.trembl.org/codec/536/</link>
		<comments>http://www.trembl.org/codec/536/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 10:15:07 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[method]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/536/</guid>
		<description><![CDATA[MyClassWithDelegate.h #import &#60;Cocoa/Cocoa.h&#62; &#160; @protocol MyClassWithDelegaet &#60;NSObject&#62; @optional - &#40;void&#41;myDelegateMethod:&#40;NSString*&#41;tsst; @end &#160; @interface MyClassWithDelegate : NSView &#123; id &#60;MyClassWithDelegate&#62; delegate; &#125; &#160; @property &#40;nonatomic, assign&#41; id &#60;MyClassWithDelegate&#62; delegate; &#160; @end &#160; MyClassWithDelegate.m #import &#34;MyClassWithDelegate.h&#34; &#160; @implementation MainView &#160; @synthesize delegate; &#160; - &#40;void&#41;anyEvent:&#40;NSEvent *&#41;e &#123; // an event or something like that // send delegate [...]]]></description>
			<content:encoded><![CDATA[<p>MyClassWithDelegate.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Cocoa/Cocoa.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> MyClassWithDelegaet &lt;NSObject&gt;
@optional
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>myDelegateMethod<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>tsst;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MyClassWithDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSView</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">id</span> &lt;MyClassWithDelegate&gt; delegate;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span> &lt;MyClassWithDelegate&gt; delegate;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>&nbsp;</p>
<p>MyClassWithDelegate.m</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;MyClassWithDelegate.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> MainView
&nbsp;
<span style="color: #a61390;">@synthesize</span> delegate;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>anyEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSEvent</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>e <span style="color: #002200;">&#123;</span> <span style="color: #11740a; font-style: italic;">// an event or something like that</span>
	<span style="color: #11740a; font-style: italic;">// send delegate</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self delegate<span style="color: #002200;">&#93;</span> myDelegateMethod<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;sss&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Thanks to Jon Sterling for his<a href="http://jonsterling.github.com/2009/08/01/using-custom-delegates-in-objective-c.html"> digest </a> of Apple&#8217;s &#8216;<a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW26">How Delegation Works</a>&#8216;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/536/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delay method execution, part II</title>
		<link>http://www.trembl.org/codec/374/</link>
		<comments>http://www.trembl.org/codec/374/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 09:13:09 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[delay]]></category>
		<category><![CDATA[execution]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[NSTimer]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/?p=374</guid>
		<description><![CDATA[&#91;NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector: @selector&#40;methodName:&#41; userInfo:nil repeats:NO&#93;; Alternative to Part I [35], has the possibility of repetetive calls.]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSTimer</span> scheduledTimerWithTimeInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span> 
target<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span> <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>methodName<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>  
userInfo<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> repeats<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Alternative to <a href="http://www.trembl.org/codec/35/">Part I [35]</a>, has the possibility of repetetive calls.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/374/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delay method execution &amp; passing objects along the way</title>
		<link>http://www.trembl.org/codec/58/</link>
		<comments>http://www.trembl.org/codec/58/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 10:31:46 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[delay]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[performSelector]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/?p=58</guid>
		<description><![CDATA[Specific example. Deselect table cell after a certain time. TableView and indexPath are wrapped into an array and send along to the method for delayed execution. - (void)tableView:(UITableView *)tView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"User selected row %d\n", [indexPath row] + 1); // actions [self performSelector:@selector(deselectTableCell:) withObject:[NSArray arrayWithObjects:tView, indexPath, nil] afterDelay:0.2f]; } -(void) deselectTableCell:(NSArray *)array { [[ [...]]]></description>
			<content:encoded><![CDATA[<p>Specific example. Deselect table cell after a certain time. TableView and indexPath are wrapped into an array and send along to the method for delayed execution.</p>
<p><code><br />
- (void)tableView:(UITableView *)tView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {<br />
	NSLog(@"User selected row %d\n", [indexPath row] + 1);<br />
	// actions<br />
	[self performSelector:@selector(deselectTableCell:) withObject:[NSArray arrayWithObjects:tView, indexPath, nil] afterDelay:0.2f];<br />
}</p>
<p>-(void) deselectTableCell:(NSArray *)array {<br />
	[[ [array objectAtIndex:0] cellForRowAtIndexPath:[array objectAtIndex:1] ] setSelected:NO];<br />
	NSLog(@"deselectTableCell" );<br />
}<br />
</code></p>
<p>In additon to <a href="http://www.trembl.org/codec/35/">http://www.trembl.org/codec/35/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/58/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Delay method execution</title>
		<link>http://www.trembl.org/codec/35/</link>
		<comments>http://www.trembl.org/codec/35/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:08:03 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[delay]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/?p=35</guid>
		<description><![CDATA[[self performSelector:@selector(methodName) withObject:nil afterDelay:0.10f]; update: http://www.trembl.org/codec/58/]]></description>
			<content:encoded><![CDATA[<p>[self performSelector:@selector(methodName) withObject:nil afterDelay:0.10f];</p>
<p>update: <a href="http://www.trembl.org/codec/58/">http://www.trembl.org/codec/58/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/35/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

