https://ccrma.stanford.edu/mediawiki/index.php?title=MoPhO/iPhoneDevelopment&feed=atom&action=historyMoPhO/iPhoneDevelopment - Revision history2024-03-29T12:18:39ZRevision history for this page on the wikiMediaWiki 1.24.1https://ccrma.stanford.edu/mediawiki/index.php?title=MoPhO/iPhoneDevelopment&diff=9291&oldid=prevJorgeh: /* Code snippets */2009-11-12T20:33:01Z<p><span dir="auto"><span class="autocomment">Code snippets</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 20:33, 12 November 2009</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>= Code snippets =</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>= Code snippets =</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">'''Pleas add any snippet of code that you think might be helpful to others.'''</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>=== Update view from a different thread (not the main thread) ===</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>=== Update view from a different thread (not the main thread) ===</div></td></tr>
<!-- diff cache key wikidb-ccrma_:diff:version:1.11a:oldid:9285:newid:9291 -->
</table>Jorgehhttps://ccrma.stanford.edu/mediawiki/index.php?title=MoPhO/iPhoneDevelopment&diff=9285&oldid=prevJorgeh: Created page with '= Code snippets = === Update view from a different thread (not the main thread) === If you have a function that runs on a different thread and you want to update something in a…'2009-11-12T20:21:03Z<p>Created page with '= Code snippets = === Update view from a different thread (not the main thread) === If you have a function that runs on a different thread and you want to update something in a…'</p>
<p><b>New page</b></p><div>= Code snippets =<br />
<br />
=== Update view from a different thread (not the main thread) ===<br />
<br />
If you have a function that runs on a different thread and you want to update something in a View, you will need to add a <code>NSAutoreleasePool</code> to that thread (or at least the function) and then you need to call the <code>performSelectorOnMainThread</code> method on the view or object you are updating.<br />
<br />
For example, assuming that <code>data</code> is a pointer to a <code>UILabel</code> in the view that we want to update in the callback:<br />
<br />
<pre><br />
// Function not running in the Main Thread <br />
void callback( void * data )<br />
{<br />
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];<br />
UILabel * me = (UILabel *)data;<br />
[me performSelectorOnMainThread:@selector(setText:) withObject:@"New text" waitUntilDone:YES];<br />
[autoreleasepool release];<br />
}<br />
</pre><br />
<br />
Instead of a <code>UILabel</code> you can pass any other widget.</div>Jorgeh