<?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>Blog d'un développeur multi-support &#187; tutoriel</title>
	<atom:link href="http://www.oni-ecchi.info/blog/tag/tutoriel/feed" rel="self" type="application/rss+xml" />
	<link>http://www.oni-ecchi.info/blog</link>
	<description>[DIM] pour les intimes :)</description>
	<lastBuildDate>Fri, 18 Jun 2010 06:27:38 +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 &amp; UITableView &amp; UISearchBar</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-uitableview-uisearchbar.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-uitableview-uisearchbar.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 10:50:44 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[tutoriel]]></category>
		<category><![CDATA[UISearchBar]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=514</guid>
		<description><![CDATA[Bonjour, je recommence à développer sur iphone après quelques mois  d&#8217;arrêt, j&#8217;en profite aussi pour tester l&#8217;Ipad (sur simulateur :p).
Cette  semaine j&#8217;ai cherché à faire fonctionner une UISearchBar avec le  controller qui va bien et j&#8217;ai eu quelque souci. Si techniquement c&#8217;est  assez simple à mettre en place, graphiquement j&#8217;ai eu [...]]]></description>
			<content:encoded><![CDATA[<p>Bonjour, je recommence à développer sur iphone après quelques mois  d&#8217;arrêt, j&#8217;en profite aussi pour tester l&#8217;Ipad (sur simulateur :p).</p>
<p>Cette  semaine j&#8217;ai cherché à faire fonctionner une UISearchBar avec le  controller qui va bien et j&#8217;ai eu quelque souci. Si techniquement c&#8217;est  assez simple à mettre en place, graphiquement j&#8217;ai eu quelque souci.</p>
<h3>Mon architecture :</h3>
<p>Mon application a une UITabBar, puis sur une des sous vue j&#8217;ai une  liste de résultat avec la SearchBar. Cet écran n&#8217;est pas  directement  une UITableView, c&#8217;est un navigation controller qui contient une UITableView.</p>
<p><img src="http://www.oni-ecchi.info/blog/wp-content/uploads/2010/02/Capture-decran-2010-02-14-à-09.15.34.png" alt="Mon archi" border="0" width="480" height="128" /></p>
<p>Ma UITableView est crée directement en code et est à hauteur fixe, et mes cellules ont une hauteur de 60:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p514code4'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5144"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p514code4"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>viewDidLoad <span style="color: #009900;">&#123;</span>  
	CGRect frame <span style="color: #339933;">=</span> CGRectMake<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">75</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">262</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Initialise une table view.</span>
	myTableView <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>UITableView alloc<span style="color: #009900;">&#93;</span> initWithFrame<span style="color: #339933;">:</span>frame<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	myTableView.<span style="color: #202020;">rowHeight</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">60</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Ajout la tableView à l'écran et autres par la suite</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4> Mes soucis </h4>
<p>﻿Les soucis viennent quand j&#8217;utilise la barre de recherche:</p>
<ul>
<li>
		Les cellules sont bien réutilisées mais la hauteur est celle par défaut du coup tout mes items sont mal 		placés. Joli bug graphique.
	</li>
<li>
		Mes résultats sont bien filtrés, mais il est impossible de scroller. La liste revient toujours en haut. Comme si ma liste avait une hauteur tellement grande que le scroll était inefficace.
	</li>
</ul>
<h4> Solutions</h4>
<p>Bon, j&#8217;en suis pas vraiment fier, ça tient plus de hooks qu&#8217;autres choses mais ça a le mérite de marcher et ça n&#8217;a pas l&#8217;air trop lourd en terme de performance sur mon 3GS.</p>
<p>En fait c&#8217;est simple, à chaque fois il faut refixer les hauteurs au moment oppertun.</p>
<ul>
<li> Pour les cellules, c&#8217;est à leur initialisation :

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p514code5'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5145"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p514code5"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>CGFloat<span style="color: #009900;">&#41;</span> tableView<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>UITableView <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> tableView heightForRowAtIndexPath<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSIndexPath <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> indexPath
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">60</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>
		Pour la liste, c&#8217;est quand on lance une recherche :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p514code6'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5146"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p514code6"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>filterContentForSearchText<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSString<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>searchText scope<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSString<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>scope
<span style="color: #009900;">&#123;</span>
	CGRect frame <span style="color: #339933;">=</span> CGRectMake<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">75</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">262</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>self searchDisplayController<span style="color: #009900;">&#93;</span> searchResultsTableView<span style="color: #009900;">&#93;</span> setFrame<span style="color: #339933;">:</span>frame<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// faire sa recherche ensuite</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
</ul>
<p>Donc en terme de performance y doit y avoir moyen de fixer ses tailles une fois pour toute mais je n&#8217;ai pas trouvé comment. Si quelqu&#8217;un a la solution je suis preneur.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-uitableview-uisearchbar.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony 1.2, behavior doctrine en actions</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html#comments</comments>
		<pubDate>Sat, 03 Oct 2009 21:49:46 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=478</guid>
		<description><![CDATA[J&#8217;ai (re)découvert un truc vraiment sympathique au boulot c&#8217;est le système de behavior doctrine intégré à symfony.
Hein ? Mais à quoi ça sert ?
Ce que j&#8217;en retiens c&#8217;est que cela peut permettre d&#8217;automatiser certaines actions (répétitives) à l&#8217;enregistrement en base, et donc d&#8217;enrichir son modèle et deux coup de cuillère à pot.
Prenons un exemple, vous [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai (re)découvert un truc vraiment sympathique au boulot c&#8217;est le système de <strong>behavior doctrine</strong> intégré à symfony.</p>
<p><strong>Hein ? Mais à quoi ça sert ?</strong></p>
<p>Ce que j&#8217;en retiens c&#8217;est que cela peut permettre d&#8217;<strong>automatiser certaines actions</strong> (répétitives) à l&#8217;enregistrement en base, et donc d&#8217;enrichir son modèle et deux coup de cuillère à pot.</p>
<p><strong>Prenons un exemple,</strong> vous devez faire un site basé sur la créations de contenus par vos utilisateurs. Ils peuvent écrire des billets, commenter, s&#8217;envoyer des messages privés, gérer un annuaire .. bref un site où l&#8217;on doit quasiment tout relié à un utilisateur. Chaques tables auraient donc au moins un &laquo;&nbsp;user_id&nbsp;&raquo; comme clée étrangère ce qui implique dans vos actions d&#8217;associer l&#8217;utilisateur courant à l&#8217;objet pour le sauvegarder .. et ce pour chaque table &#8230; lourd non ?</p>
<p>Hé bien grâce aux behaviors vous pouvez sortir ce comportement générique dans des classes et avec seulement de la configuration au niveau de votre schéma, vous pouvez associer ce comportement à n&#8217;importe quel table. L&#8217;exemple que j&#8217;ai pris est tiré du behavior &laquo;&nbsp;<em>Signable</em>&nbsp;&raquo; du plugin <span><em>sfDoctrineActAsSignablePlugin</em>.</span></p>
<h3>Configuration</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code12'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47812"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p478code12"><pre class="yml" style="font-family:monospace;">Item:
  actAs:
    Signable:
  columns:
    id:
      type:             integer
      primary:          true
      autoincrement:    true
    champ1:             string(255</pre></td></tr></table></div>

<h3>Comment ça marche ?</h3>
<p>Donc si on résume, il faut dire à Doctrineque l&#8217;on va rajouter des colonnes .. et que l&#8217;on veut être prévénu lors de l&#8217;insertion en base pour associé nos actions. Donc avec seulement 2 classes, une de définition et une d&#8217;écoute, on peut s&#8217;en sortir et crée notre behavior.</p>
<p>Lors de la configuration, en rajoutant &laquo;&nbsp;actAs : Signable&nbsp;&raquo;, Doctrine va chercher une classe de définition qui ira  étendre une classe Doctrine_Template. Par convention il ira chercher une classe nommé Doctrine_Template_Signable. Le rôle de cette classe est de déclarer ses colonnes et de rajouter une écoute, un listener, vers l&#8217;autre classe d&#8217;actions.</p>
<p>Pour mon exemple, je vais volontairement raccourcir les classes du sfDoctrineActAsSignablePlugin et prendre pour acquis que vos utilisateurs sont gérés via sfGuardDoctrinePlugin.</p>
<h3>Doctrine_Template</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47813"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p478code13"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Doctrine_Template_Signable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Template <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Définitions des relations</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Bim rajoute une clée étrangère sur sfGuard</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasOne</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sfGuardUser as Author'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'local'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'created_by'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'foreign'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span>
            <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Bim une colonne en plus</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_by'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'4'</span><span style="color: #339933;">,</span>
     <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Lien avec notre 2eme classe .. on passe le nom de la colonnette rajouté</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Doctrine_Template_Listener_Signable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_by));
  }
}</span></pre></td></tr></table></div>

<p>Là pour l&#8217;exemple aucune configuration au niveau du schéma n&#8217;est possible mais c&#8217;est facile à rajouter via d&#8217;un tableau d&#8217;options et le constructeur suivant :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47814"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p478code14"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_options <span style="color: #339933;">=</span> Doctrine_Lib<span style="color: #339933;">::</span><span style="color: #004000;">arrayDeepMerge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_options<span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Doctrine_Template_Listener</h3>
<p>Nous avons vu que notre Template rajoute un listener vers notre 2e classe en lui passant la colonne à surveiller (dans la vrai vie, un tableau d&#8217;options ..). Le rôle de notre listener de pouvoir agir avant/après l&#8217;insertion/édition d&#8217;un objet .. facile :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47815"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code" id="p478code15"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Doctrine_Template_Listener_Signable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record_Listener <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_colonette</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;created_by&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$colonne</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_colonette <span style="color: #339933;">=</span> <span style="color: #000088;">$colonne</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preInsert<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$createdName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_colonette<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// recupère l'objet appellant :</span>
      <span style="color: #000088;">$objet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvoker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Affectation de valeur</span>
       <span style="color: #000088;">$objet</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$createdName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUserId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// Echappe le mode cli</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">!=</span> <a href="http://www.php.net/strncasecmp"><span style="color: #990000;">strncasecmp</span></a><span style="color: #009900;">&#40;</span>PHP_SAPI<span style="color: #339933;">,</span> <span style="color: #0000ff;">'cli'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #666666; font-style: italic;">// L'user courant</span>
       <span style="color: #b1b100;">return</span> sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sfGuardSecurityUser'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preUpdate<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postUpdate<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postInsert<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// A tester : public function Delete(Doctrine_Event $event) ..</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p> Vous n&#8217;avez plus qu&#8217;a rebuilder votre model et magie ça doit marcher !! </p>
<p> Vu que l&#8217;on a fait une relation de type One-to-many sur sfGuard vous pouvez accéder à l&#8217;utilisateur sfGuard via la propriété Author sur n&#8217;importr quel table marqué comme &laquo;&nbsp;Signable&nbsp;&raquo; </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47816"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p478code16"><pre class="php" style="font-family:monospace;">  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$objet</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Author</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Voilà .. simple au final  non ? Ah vous de créez le votre, :p</p>
<p>Comme on dirait au boulot &laquo;&nbsp;Amaaziiiing !!&nbsp;&raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Débuter sur le développement iPhone</title>
		<link>http://www.oni-ecchi.info/blog/iphone/debuter-sur-le-developpement-iphone.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/debuter-sur-le-developpement-iphone.html#comments</comments>
		<pubDate>Thu, 23 Jul 2009 07:49:07 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=428</guid>
		<description><![CDATA[Salut,
Il m&#8217;est arrivé plusieurs fois qu&#8217;on me demande ce qu&#8217;il faut pour bien débuter sur iPhone. La question est simple, la réponse un peu moins. Je vais commencer par le plus simple, le matériel.
Matériel :

un Mac intel. Désolé mais vos vieux mac à la cave ne marcheront pas.
un iPhone de test. Le simulateur ne suffit [...]]]></description>
			<content:encoded><![CDATA[<p>Salut,<br />
Il m&#8217;est arrivé plusieurs fois qu&#8217;on me demande ce qu&#8217;il faut pour bien débuter sur <a class="zem_slink" title="iPhone" rel="homepage" href="http://www.apple.com/iphone">iPhone</a>. La question est simple, la réponse un peu moins. Je vais commencer par le plus simple, le matériel.</p>
<h3>Matériel :</h3>
<ul>
<li><strong>un Mac intel</strong>. Désolé mais vos vieux mac à la cave ne marcheront pas.</li>
<li>un <strong>iPhone de test</strong>. Le simulateur ne suffit pas.</li>
<li>une<strong> licence de développeur Apple</strong>. (Pas bien cher, 70€ je crois ..). Ceux qui disent  &laquo;&nbsp;Mais moi je jailbreak j&#8217;envoie mes appli en SSH et fuck Apple&nbsp;&raquo; je leur répond &laquo;&nbsp;Vous vous faites bien chier.&nbsp;&raquo; Et les solutions pour auto signer son code pour l&#8217;envoyer &laquo;&nbsp;comme en vrai&nbsp;&raquo; c&#8217;est pas trop la joie (faut refaire les manips pour chaque projets ..)</li>
</ul>
<p>Sinon pour développer sur PC (windows notamment) sachez qu&#8217;on peut compiler des applis et se les envoyer en SSH etc. C&#8217;est faisable, mais alors quel perte de temps et vous verrez dans la suite de l&#8217;article qu&#8217;on y gagne pas tant que ça.</p>
<h3>Logiciels :</h3>
<ul>
<li><strong>Xcode </strong>le seul et unique <a class="zem_slink" title="Integrated development environment" rel="nofollow" href="http://en.wikipedia.org/wiki/Integrated_development_environment">IDE</a> sympathique. Il auto-complète un peu, permet de compiler directement sur le téléphone sans prise de tête, fourni un debugger pas à pas.</li>
<li><strong><a class="zem_slink" title="Interface Builder" rel="wikipedia" href="http://en.wikipedia.org/wiki/Interface_Builder">Interface Builder</a></strong>. Ça c&#8217;est le truc tape à l&#8217;oeil  qu&#8217;Apple met en avant. C&#8217;est pour construire les écrans et relier les éléments graphiques à leurs représentations &laquo;&nbsp;code&nbsp;&raquo;. C&#8217;est super pratique et beaucoup plus ergonomique que de le faire sur <a class="zem_slink" title="Android" rel="homepage" href="http://code.google.com/android/">Android</a> :
<pre>// Lie les champs graphiques à des champs codes
EditText login = (EditText) findViewById(R.id.login);</pre>
</li>
<li><strong>Instruments</strong>. Super pratique pour voir l&#8217;état en temps réel de l&#8217;iphone : consommation CPU, RAM, allocations d&#8217;objets etc. C&#8217;est avec ce genre d&#8217;outils que tu te dis &laquo;&nbsp;en fait je ne sais pas coder léger&nbsp;&raquo;</li>
</ul>
<p>Donc on voit bien que même s&#8217;il existe des solutions pour compiler sur PC, les &laquo;&nbsp;<a rel="nofollow" href="toolchain iphone" target="_blank">toolchain iphone</a>&nbsp;&raquo; c&#8217;est quand même dommage de se séparer de ces logiciels. Encore que pour Xcode eclipse doit pouvoir suffir, les deux autres logiciels n&#8217;ont pas l&#8217;air d&#8217;avoir d&#8217;équivalent.</p>
<p>Et puis la finalité de développer sur iPhone c&#8217;est bien d&#8217;avoir son quart d&#8217;heure de gloire sur l&#8217;appStore non ? Alors autant commencer bien et dans la légalité. Car si Apple découvre que vous n&#8217;avez pas utilisé ses outils, que votre appli est dispo en jailbreak etc .. ben c&#8217;est foutu après.</p>
<h3>Langage de programmation</h3>
<p>Je suis passé par 3 phases quand j&#8217;ai commencé à programmer en <strong>objective-c</strong>.</p>
<ul>
<li>Déroutant au début (retain une variable ? Kesako ?)</li>
<li>a l&#8217;air d&#8217;avoir des mécanismes complexes (le parsage d&#8217;XML est chelou quand on vient du web php/as3 etc)</li>
<li>Pratique et puissant quand on comprend les mécanismes par <a class="shal" href=" http://www.oni-ecchi.info/blog/iphone/iphone-delegate.html" title=" iPhone & Delegate">delegate</a>, que l&#8217;on joue avec les threads, que l&#8217;on crée ses propres classes outils (comme pour ma classe de <a class="shal" href=" http://www.oni-ecchi.info/blog/iphone/iphone-requete-http.html" title=" iPhone & Requete HTTP">requete http</a>)</li>
</ul>
<p>Mais comment apprendre ce langage ? la réponse est simple : dans la documentation.</p>
<h3>Documentation et Tutoriel</h3>
<p>La documentation et les guides Apple sont bien pratiques pour appréhender le langage et les mécanismes.</p>
<p>Cependant pour appréhender Interface Builder et sa relation avec le code c&#8217;est pas trop ça. Je conseille les tutos d<a rel="nofollow" href="http://ipup.fr/tutoriels.php" target="_blank">&#8216;ipup.fr</a> qui ont pas mal d&#8217;images et surtout que c&#8217;est français. </p>
<p>Sinon pour plus de liens, je vous conseille toujours les liens de mon précédent article &laquo;&nbsp;<a class="shal" href=" http://www.oni-ecchi.info/blog/iphone/creer-des-applications-iphone.html" title=" Créer des applications Iphone">créer des applications iphone</a>&nbsp;&raquo; et mon flux delicious :</p>
<p><cite class="aligncenter">ps : Si vous voulez suivre mes « découvertes » iphone,  mon flux delicious est constamment mis à jour ! <a href="http://delicious.com/onishinji/iphone">http://delicious.com/onishinji/iphone</a></cite></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/debuter-sur-le-developpement-iphone.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>iPhone &amp; NSTimer</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-nstimer.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-nstimer.html#comments</comments>
		<pubDate>Fri, 17 Jul 2009 09:27:00 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=414</guid>
		<description><![CDATA[Salut,
Les NSTimers sont bien cool et en général ça ne pose aucun souci à les utiliser. J&#8217;ai bien dit en général. J&#8217;ai eu un souci avec ce matin&#8230;vraiment étrange.
Sur un projet, j&#8217;en utilise un pour déclencher une méthode dans XX secondes une fois seulement. Ça marche impeccable. Sur un nouveau projet, je réutilise le même [...]]]></description>
			<content:encoded><![CDATA[<p>Salut,</p>
<p>Les NSTimers sont bien cool et en général ça ne pose aucun souci à les utiliser. J&#8217;ai bien dit en général. J&#8217;ai eu un souci avec ce matin&#8230;vraiment étrange.</p>
<p>Sur un projet, j&#8217;en utilise un pour déclencher une méthode dans XX secondes une fois seulement. Ça marche impeccable. Sur un nouveau projet, je réutilise le même mais en faisant varier un paramètre &laquo;&nbsp;repeats&nbsp;&raquo; à YES. Et bien sur, ça ne marchait plus.</p>
<p>Voici un timer qui déclenche une méthode une seule fois :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p414code20'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p41420"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p414code20"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>blabla
<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#91;</span>NSTimer scheduledTimerWithTimeInterval<span style="color: #339933;">:</span><span style="color:#800080;">10.0</span> target<span style="color: #339933;">:</span>self selector<span style="color: #339933;">:</span>@selector<span style="color: #009900;">&#40;</span>test<span style="color: #339933;">:</span><span style="color: #009900;">&#41;</span> userInfo<span style="color: #339933;">:</span>nil repeats<span style="color: #339933;">:</span>NO<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>test<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSTimer<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>timer
<span style="color: #009900;">&#123;</span>
	NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;je suis appelé 1 fois&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Un timer qui se déclenche une méthode en boucle, techniquement il faudrait juste dire &laquo;&nbsp;repeats:YES&nbsp;&raquo; mais ca n&#8217;a pas marché dans mon cas. Le timer n&#8217;était jamais &laquo;&nbsp;fired&nbsp;&raquo; :p (je m&#8217;essaie à l&#8217;anglais)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p414code21'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p41421"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p414code21"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>blabla
<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#91;</span>NSTimer scheduledTimerWithTimeInterval<span style="color: #339933;">:</span><span style="color:#800080;">10.0</span> target<span style="color: #339933;">:</span>self selector<span style="color: #339933;">:</span>@selector<span style="color: #009900;">&#40;</span>test<span style="color: #339933;">:</span><span style="color: #009900;">&#41;</span> userInfo<span style="color: #339933;">:</span>nil repeats<span style="color: #339933;">:</span>YES<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>test<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSTimer<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>timer
<span style="color: #009900;">&#123;</span>
	NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;je suis appelé en boucle c'est la fête.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Donc voici ce que j&#8217;ai utilisé pour que ça marche. J&#8217;ai forcé le démarrage du timer en boucle.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p414code22'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p41422"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p414code22"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>blabla
<span style="color: #009900;">&#123;</span>
	NSTimer <span style="color: #339933;">*</span> timer <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSTimer timerWithTimeInterval<span style="color: #339933;">:</span> <span style="color: #0000dd;">1</span> target<span style="color: #339933;">:</span> self selector<span style="color: #339933;">:</span> @selector<span style="color: #009900;">&#40;</span>test<span style="color: #339933;">:</span><span style="color: #009900;">&#41;</span> userInfo<span style="color: #339933;">:</span> nil repeats<span style="color: #339933;">:</span> YES<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSRunLoop mainRunLoop<span style="color: #009900;">&#93;</span> addTimer<span style="color: #339933;">:</span> timer forMode<span style="color: #339933;">:</span> NSDefaultRunLoopMode<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>test<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSTimer<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>timer
<span style="color: #009900;">&#123;</span>
	NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;je suis appelé en boucle c'est la fête.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Voilà voilà</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-nstimer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone &amp; Trucs et Astuces</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-trucs-et-astuces.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-trucs-et-astuces.html#comments</comments>
		<pubDate>Tue, 14 Jul 2009 09:46:53 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=370</guid>
		<description><![CDATA[Bonjour tout le monde, encore de l&#8217;iphone .. et ouais j&#8217;aime bien faire des petits exemples :p
Cette fois ci à la demande non général de Sébastien H. voici quelques éléments de navigation que j&#8217;utilise dans mes applications.  Donc voici ce qu&#8217;il y a dans cet exemple :

Comment créer et utiliser les préférences utilisateurs à travers [...]]]></description>
			<content:encoded><![CDATA[<p>Bonjour tout le monde, encore de l&#8217;iphone .. et ouais j&#8217;aime bien faire des petits exemples :p</p>
<p>Cette fois ci à la demande non général de Sébastien H. voici quelques éléments de navigation que j&#8217;utilise dans mes applications.  Donc voici ce qu&#8217;il y a dans cet exemple :</p>
<ul>
<li>Comment créer et utiliser les préférences utilisateurs à travers l&#8217;objet NSUserDefaults et le fichier settings.bundle :p</li>
<li>Comment créer une vue modal. Vous savez ce genre d&#8217;écrans qui arrivent par le bas de l&#8217;application et qui repartent ensuite.</li>
<li>Je refait aussi un petit rappel sur les <a class="shal" href=" http://www.oni-ecchi.info/blog/iphone/iphone-delegate.html" title=" iPhone & Delegate">delegate iphone</a> pour la vue modal.</li>
<li>Comment créer et utiliser le fameux menu d&#8217;actions à la façon safari pour permettre de fournir des boutons qui arrivent aussi par le bas de l&#8217;application (UIActionSheet)</li>
<li>Comment ouvrir d&#8217;autres applications installées sur l&#8217;iphone grâce à la méthode [UIApplication sharedApplication] :p</li>
</ul>
<p>On m&#8217;a dit qu&#8217;il manquait un peu d&#8217;images, voici des screenshoots de l&#8217;application d&#8217;exemple :</p>
<p><img src="http://www.oni-ecchi.info/blog/wp-content/uploads/2009/07/Image-1.png" alt="" width="209" height="315" /><img src="http://www.oni-ecchi.info/blog/wp-content/uploads/2009/07/Image-2.png" alt="" width="209" height="315" /></p>
<p>Le design est assez simple ;p</p>
<p><cite>Et n&#8217;oubliez pas de télécharger <a rel="attachment wp-att-378" href="http://www.oni-ecchi.info/blog/iphone/iphone-trucs-et-astuces.html/attachment/exemple-navigation">le projet Xcode de cet exemple</a></cite></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-trucs-et-astuces.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone &amp; Requete HTTP</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-requete-http.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-requete-http.html#comments</comments>
		<pubDate>Thu, 09 Jul 2009 11:15:45 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[nsurlrequest]]></category>
		<category><![CDATA[requete]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=345</guid>
		<description><![CDATA[Yop all,
A la demande général de Fabrice Bernhard, voici une classe que j&#8217;ai faite pour me simplifier la vie quand je dois faire une requête HTTP. Vous me direz &#171;&#160;pas besoin blabla&#160;&#187;, mais cette classe gère l&#8217;envoie d&#8217;images, de sons en plus de simple paramètres POST classique. Vous faites moins les malins hein :) Et [...]]]></description>
			<content:encoded><![CDATA[<p>Yop all,</p>
<p>A la demande général de Fabrice Bernhard, voici une classe que j&#8217;ai faite pour me simplifier la vie quand je dois faire une requête <a class="zem_slink" title="Hypertext Transfer Protocol" rel="wikipedia" href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>. Vous me direz &laquo;&nbsp;pas besoin blabla&nbsp;&raquo;, mais cette classe gère l&#8217;envoie d&#8217;images, de sons en plus de simple paramètres POST classique. Vous faites moins les malins hein :) Et si je vous dit qu&#8217;elle gère aussi si la requête doit être fait en mode synchrone ou asynchrone hein ? Ça t&#8217;en bouche un coin ?</p>
<p>Bah en fait elle est très simple, j&#8217;ai juste joué au légo avec les classes <a class="zem_slink" title="Apple" rel="homepage" href="http://www.apple.com">Apple</a>, mais c&#8217;est un lego qui me sert pas mal.</p>
<p>Voici un exemple d&#8217;utilisation, ce code est tiré de l&#8217;exemple que j&#8217;ai fait pour vous, disponible en téléchargement :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p345code25'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34525"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p345code25"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span> send
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Crée la requete en mode asynchrone</span>
HttpRequest <span style="color: #339933;">*</span>masuperRequete <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>HttpRequest alloc<span style="color: #009900;">&#93;</span> initHttpRequest<span style="color: #339933;">:</span>formUrlAsk.<span style="color: #202020;">text</span> isSynchronous<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Ajoute un parametre POST['cleParam'];</span>
<span style="color: #009900;">&#91;</span>masuperRequete addParam<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;cleParam&quot;</span> valeurs<span style="color: #339933;">:</span>formParam.<span style="color: #202020;">text</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Ajoute un fichier Image. Les parametres seront sous la forme file1, file2, file3 .. etc</span>
<span style="color: #009900;">&#91;</span>masuperRequete addImage<span style="color: #339933;">:</span>imageTmp.<span style="color: #202020;">image</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ajoute un son</span>
<span style="color: #666666; font-style: italic;">// On doit recuperer les données du son sous la forme d'un NSDATA</span>
<span style="color: #666666; font-style: italic;">// Ici le son est distant .. on le recupère donc avec the super classe en mode syncrhone</span>
HttpRequest <span style="color: #339933;">*</span>sousReq <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>HttpRequest alloc<span style="color: #009900;">&#93;</span> initHttpRequest<span style="color: #339933;">:</span>formUrlSound.<span style="color: #202020;">text</span> isSynchronous<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
NSData <span style="color: #339933;">*</span> dataSound <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>sousReq send<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Recupere le nom du son</span>
NSArray <span style="color: #339933;">*</span> mots <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>formUrlSound.<span style="color: #202020;">text</span> componentsSeparatedByString<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
NSString <span style="color: #339933;">*</span>nameoffile <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>mots lastObject<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>masuperRequete addSound<span style="color: #339933;">:</span>dataSound nameoffile<span style="color: #339933;">:</span>nameoffile nameinform<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;mamusique&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Envoie la superRequete</span>
masuperRequete.<span style="color: #202020;">delegate</span> <span style="color: #339933;">=</span> self<span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>masuperRequete send<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// y a un delegate pour recup le retour de la requete en mode asynchrone</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>downloadFinish<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSMutableData <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>data
<span style="color: #009900;">&#123;</span>
NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;telechargement termine&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Maintenant voici le code source complet de l&#8217;exemple</p>
<p><cite><a rel="attachment wp-att-348" href="http://www.oni-ecchi.info/blog/iphone/iphone-requete-http.html/attachment/exemple-post">Exemple de la classe HTTPRequest</a></cite></p>
<p>Pour récupérer les données par la suite, rien de plus simple tout est dans $_POST et $_FILES.</p>
<p><strong>maj</strong> : voilà le code source du fichier php que j&#8217;ai utilisé :</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p345code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34526"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
</pre></td><td class="code" id="p345code26"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$content_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'upload/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;variable POST : <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cle</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$cle</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' =&gt; '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'monson'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/base64_decode"><span style="color: #990000;">base64_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'monson'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;upload/son.caf&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;w+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			fclode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;variable FILES : <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cle</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$tmp_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/is_uploaded_file"><span style="color: #990000;">is_uploaded_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp_file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Le fichier est introuvable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// on vérifie maintenant l'extension</span>
				<span style="color: #000088;">$type_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/strstr"><span style="color: #990000;">strstr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$type_file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span><span style="color: #666666; font-style: italic;">#038;&amp;#038; !strstr($type_file, 'jpeg') &amp;#038;&amp;#038; !strstr($type_file, 'bmp') &amp;#038;&amp;#038; !strstr($type_file, 'png') &amp;#038;&amp;#038; !strstr($type_file, 'gif') )
</span>				<span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//exit(&quot;Le fichier n'est pas une image&quot;);</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// on copie le fichier dans le dossier de destination</span>
				<span style="color: #000088;">$name_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$cle</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; =&gt; &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$name_file</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; reçu <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/move_uploaded_file"><span style="color: #990000;">move_uploaded_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content_dir</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$name_file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Impossible de copier le fichier dans <span style="color: #006699; font-weight: bold;">$content_dir</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	 <span style="color: #000088;">$rep</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;upload/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/opendir"><span style="color: #990000;">opendir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rep</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/readdir"><span style="color: #990000;">readdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  	 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_file"><span style="color: #990000;">is_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rep</span><span style="color: #339933;">.</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;Nom : &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$f</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;upload/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$f</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt; DL &lt;/a&gt;'</span><span style="color: #339933;">;</span>
      		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;Taille : &quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rep</span><span style="color: #339933;">.</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; octets&quot;</span><span style="color: #339933;">;</span>
      		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
   		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Précisons quand même que ma classe est en alpha, certaines fonctionnalités ne sont pas implémentés. Je pense notamment à la gestion des erreurs, le delegate qui donne le taux de progression de l&#8217;upload etc. Je vous laisse le faire :p</p>
<p>Enjoy !</p>
<div class="zemanta-img zemanta-action-dragged" style="margin: 1em; display: block;">
<div class="wp-caption alignleft" style="width: 210px"><a href="http://www.crunchbase.com/company/apple"><img title="Image representing Apple as depicted in CrunchBase" src="http://www.crunchbase.com/assets/images/resized/0001/0923/10923v1-max-450x450.png" alt="Image representing Apple as depicted in CrunchBase" width="200" height="122" /></a><p class="wp-caption-text">Image via CrunchBase</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-requete-http.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>iPhone &amp; AVAudioPlayer</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-avaudioplayer.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-avaudioplayer.html#comments</comments>
		<pubDate>Wed, 18 Mar 2009 16:11:19 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[avancer]]></category>
		<category><![CDATA[son]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=312</guid>
		<description><![CDATA[Aujourd&#8217;hui, j&#8217;ai bataillé pour lancer un mp3 au lancement d&#8217;une application. Tellement bataillé que je vais mettre ici le code qui va bien pour que je puisse le retrouver rapidement :) Donc peu d&#8217;explication, ceci n&#8217;est pas un tutorial.

Inclure le framework AudioToolBox &#38; AVFoundation
Faire les imports suivants : #import &#38;lt;AVFoundation/AVFoundation.h&#38;gt; #import &#38;lt;AudioToolbox/AudioToolbox.h&#38;gt;
Inclure le fichier à [...]]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui, j&#8217;ai bataillé pour lancer un mp3 au lancement d&#8217;une application. Tellement bataillé que je vais mettre ici le code qui va bien pour que je puisse le retrouver rapidement :) Donc peu d&#8217;explication, ceci n&#8217;est pas un tutorial.</p>
<ol>
<li>Inclure le framework AudioToolBox &amp; AVFoundation</li>
<li>Faire les imports suivants : #import &amp;lt;AVFoundation/AVFoundation.h&amp;gt; #import &amp;lt;AudioToolbox/AudioToolbox.h&amp;gt;</li>
<li>Inclure le fichier à jouer dans le projet dans le dossier &laquo;&nbsp;ressources&nbsp;&raquo;</li>
<li>Déclarer une propriété de classe AVAudioPlayer * audioPlayer;</li>
</ol>
<p>Et voici le code qui va bien :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p312code28'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p31228"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code" id="p312code28"><pre class="c" style="font-family:monospace;">	<span style="color: #666666; font-style: italic;">// Initialise un contexte Audio</span>
	AudioSessionInitialize <span style="color: #009900;">&#40;</span>
							NULL<span style="color: #339933;">,</span>                          <span style="color: #666666; font-style: italic;">// 'NULL' to use the default (main) run loop</span>
							NULL<span style="color: #339933;">,</span>                          <span style="color: #666666; font-style: italic;">// 'NULL' to use the default run loop mode</span>
							NULL<span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// a reference to your interruption callback</span>
							self                       <span style="color: #666666; font-style: italic;">// data to pass to your interruption listener callback</span>
							<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Definit quel type de son on va joué</span>
	UInt32 sessionCategory <span style="color: #339933;">=</span> kAudioSessionCategory_MediaPlayback<span style="color: #339933;">;</span>
	AudioSessionSetProperty <span style="color: #009900;">&#40;</span>
							 kAudioSessionProperty_AudioCategory<span style="color: #339933;">,</span>
							 <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span>sessionCategory<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
							 <span style="color: #339933;">&amp;</span><span style="color: #339933;">#038;sessionCategory</span>
							 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Définit quel fichier on utilise pour le son</span>
	NSData <span style="color: #339933;">*</span>soundFileData<span style="color: #339933;">;</span>
	soundFileData <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSData dataWithContentsOfURL<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>NSURL fileURLWithPath<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSBundle mainBundle<span style="color: #009900;">&#93;</span> pathForResource<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;music.mp3&quot;</span> ofType<span style="color: #339933;">:</span>NULL<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Initialise notre lecteur avec les données du fichiers son à jouer</span>
	audioPlayer <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>AVAudioPlayer alloc<span style="color: #009900;">&#93;</span> initWithData<span style="color: #339933;">:</span>soundFileData error<span style="color: #339933;">:</span>NULL<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Precharge le son</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>audioPlayer prepareToPlay<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;myAudioPlayer:prepareToPlay returned FALSE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Définit le delegate sur la classe courante</span>
	audioPlayer.<span style="color: #202020;">delegate</span> <span style="color: #339933;">=</span> self<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Définit le volume</span>
	<span style="color: #009900;">&#91;</span>audioPlayer setVolume<span style="color: #339933;">:</span><span style="color:#800080;">1.0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Joue le son !</span>
	<span style="color: #009900;">&#91;</span>audioPlayer play<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Voilà, la seul différence avec les codes que l&#8217;on peut trouver un peu partout est l&#8217;ajout du Session Audio. Si je l&#8217;initialise pas le son ne fonctionne que sur le simulateur et pas sur le mobile. Je ne sais pas trop pourquoi.</p>
<p>Merci à <a href="http://www.linkedin.com/in/fpillet" rel="nofollow">fpillet</a> du channel irc #iphonedev sur freenode pour son aide.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-avaudioplayer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iphone &amp; UIButton &amp; Multilangue</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-uibutton-multilangue.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-uibutton-multilangue.html#comments</comments>
		<pubDate>Sun, 08 Mar 2009 14:47:48 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[débutant]]></category>
		<category><![CDATA[multi langue]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=307</guid>
		<description><![CDATA[Vaste programme pour ce billet :) En fait nous allons modifier un bouton en fonction de la langue du téléphone.
Et nous allons créer un état &#171;&#160;survolé&#160;&#187; à notre bouton par programmation. InterfaceBuilder n&#8217;étant pas très clair sur cette manipulation.
Tout d&#8217;abord il nous faut un UIButton déclaré en tant que IBOutlet UIButton dans notre classe. Puis [...]]]></description>
			<content:encoded><![CDATA[<p>Vaste programme pour ce billet :) En fait nous allons modifier un bouton en fonction de la langue du téléphone.<br />
Et nous allons créer un état &laquo;&nbsp;survolé&nbsp;&raquo; à notre bouton par programmation. InterfaceBuilder n&#8217;étant pas très clair sur cette manipulation.</p>
<p>Tout d&#8217;abord il nous faut un UIButton déclaré en tant que IBOutlet UIButton dans notre classe. Puis nous relions ce bouton via InterfaceBuilder avec un bouton sur notre vue. Dans les propriétés de celui ci vous pouvez dire que c&#8217;est un &laquo;&nbsp;custom button&nbsp;&raquo;. Faites le. Et nous revenons à XCode : </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p307code30'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p30730"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p307code30"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>viewDidLoad
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Gestion du multilanguage</span>
	NSUserDefaults<span style="color: #339933;">*</span> defs <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSUserDefaults standardUserDefaults<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	NSArray<span style="color: #339933;">*</span> languages <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>defs objectForKey<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;AppleLanguages&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// preferredLang vaut &quot;fr&quot;, &quot;en&quot;, &quot;de&quot;, etc </span>
	preferredLang <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>languages objectAtIndex<span style="color: #339933;">:</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Méthode avec deux jeux de langues : Française ou Anglaise dans les autres langues </span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>preferredLang isEqualToString<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;fr&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		UIImage <span style="color: #339933;">*</span> higlight <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;fr_btn_clik.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>btnTest setBackgroundImage<span style="color: #339933;">:</span>higlight forState<span style="color: #339933;">:</span>UIControlStateHighlighted<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>higlight release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		UIImage <span style="color: #339933;">*</span> normal <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;fr_btn.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>btnTest setBackgroundImage<span style="color: #339933;">:</span>normal forState<span style="color: #339933;">:</span>UIControlStateNormal<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>normal release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> 
	<span style="color: #009900;">&#123;</span>
		UIImage <span style="color: #339933;">*</span> higlight <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;en_btn_clik.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>btnTest setBackgroundImage<span style="color: #339933;">:</span>higlight forState<span style="color: #339933;">:</span>UIControlStateHighlighted<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>higlight release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		UIImage <span style="color: #339933;">*</span> normal <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;en_btn.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>btnTest setBackgroundImage<span style="color: #339933;">:</span>normal forState<span style="color: #339933;">:</span>UIControlStateNormal<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#91;</span>normal release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Mais nous pouvons aussi concaténer le code langue avec le chemin de l'image.</span>
	<span style="color: #666666; font-style: italic;">// dans ce cas là il nous faut autant d'image que de langue possibles.</span>
	NSString <span style="color: #339933;">*</span> pathImage <span style="color: #339933;">=</span> @<span style="color: #ff0000;">&quot;_btn.png&quot;</span><span style="color: #339933;">;</span>
	NSString <span style="color: #339933;">*</span> pathImageClik <span style="color: #339933;">=</span> @<span style="color: #ff0000;">&quot;_btn_clik.png&quot;</span><span style="color: #339933;">;</span>
	UIImage <span style="color: #339933;">*</span> higlight <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>pathImage stringByAppendingString<span style="color: #339933;">:</span>preferredLang <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>btnTest setBackgroundImage<span style="color: #339933;">:</span>higlight forState<span style="color: #339933;">:</span>UIControlStateHighlighted<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>higlight release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	UIImage <span style="color: #339933;">*</span> normal <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>pathImageClik stringByAppendingString<span style="color: #339933;">:</span>preferredLang <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>btnTest setBackgroundImage<span style="color: #339933;">:</span>normal forState<span style="color: #339933;">:</span>UIControlStateNormal<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>normal release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Simple non ?</p>
<p>Après c&#8217;est sur cette méthode est un peu lourde. Il faut autant d&#8217;images que de langage et on n&#8217;utilise pas les techniques Apple pour le multilangue (avec leurs histoire de Bundle par langue, un dictionnaire de traductions etc).</p>
<p>Cependant, si comme vous avez affaire à des boutons très personnalisés (typo exotique, disposition du texte particuliere), il est peut être plus rapide de tout passer en image comme ici.</p>
<p>Chacun fait comme il le sent après ^^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-uibutton-multilangue.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iPhone &amp; UIView</title>
		<link>http://www.oni-ecchi.info/blog/iphone/iphone-uiview.html</link>
		<comments>http://www.oni-ecchi.info/blog/iphone/iphone-uiview.html#comments</comments>
		<pubDate>Sun, 08 Mar 2009 12:58:19 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[débutant]]></category>
		<category><![CDATA[tutoriel]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=288</guid>
		<description><![CDATA[Connaissez vous l&#8217;attribut &#171;&#160;tag&#160;&#187; d&#8217;une UIView ?
Cette propriété sert à différencier les vues les unes des autres. Il s&#8217;agit d&#8217;un entier qui, par défaut, est géré par l&#8217;iphone. Mais on peut la fixer à la main et cela permet quelque liberté. En voici une utilisation :
Admettons que vous avez une vue centrale qui sert de [...]]]></description>
			<content:encoded><![CDATA[<p>Connaissez vous l&#8217;attribut &laquo;&nbsp;tag&nbsp;&raquo; d&#8217;une UIView ?</p>
<p>Cette propriété sert à différencier les vues les unes des autres. Il s&#8217;agit d&#8217;un entier qui, par défaut, est géré par l&#8217;iphone. Mais on peut la fixer à la main et cela permet quelque liberté. En voici une utilisation :</p>
<p>Admettons que vous avez une vue centrale qui sert de menu en &laquo;&nbsp;footer&nbsp;&raquo; et que vous n&#8217;utilisez pas les composants de navigations par défaut du téléphone.</p>
<p>Lors d&#8217;un clic sur un bouton du menu &laquo;&nbsp;footer&nbsp;&raquo;, vous allez ajouter une nouvelle vue par dessus votre écran principal en laissant le footer de la vue principal visible. Seulement voilà, à chaque clic sur un bouton du menu, vous allez superposer une vue à chaque fois. Question performance c&#8217;est pas tip top.</p>
<p>Alors une première approche est déjà de faire un bouton retour dans la nouvelle vue comme ceci :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p288code35'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p28835"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p288code35"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>back <span style="color: #009900;">&#123;</span>
&nbsp;
NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;back&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">view</span> removeFromSuperview<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Mais bon rien n&#8217;empêche l&#8217;utilisateur de clicker sur les éléments du footer au lieu de faire retour. Notez que même si cette nouvelle vue est ajouté par dessus la principale et la masque complètement, les autres boutons de la vue principale sont encore actifs. Sauf si on les désactive lors du click sur le bouton et qu&#8217;on les réactives lors de l&#8217;action &laquo;&nbsp;back&nbsp;&raquo; précédemment crée, via une méthode delegate.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p288code36'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p28836"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p288code36"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// Dans la vue qui se superpose</span>
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>back <span style="color: #009900;">&#123;</span>
	NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;back&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">delegate</span> RetourMenu<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">view</span> removeFromSuperview<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Dans la vue principale</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>RetourMenu
<span style="color: #009900;">&#123;</span>
	NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;Réactivation des boutons &quot;</span>cachés<span style="color: #ff0000;">&quot; par la nouvelle superposés&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	btnVue1.<span style="color: #202020;">enabled</span> <span style="color: #339933;">=</span> YES<span style="color: #339933;">;</span>
	btnVue2.<span style="color: #202020;">enabled</span> <span style="color: #339933;">=</span> YES<span style="color: #339933;">;</span>
	btnVue3.<span style="color: #202020;">enabled</span> <span style="color: #339933;">=</span> YES<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Il faut maintenant gérer les vues afin d&#8217;éviter les superposements inutiles. Ceci se fait via la propriété tag. Personnellement j&#8217;ai définit le tag de ma vue principal à 100 via Interface Builder. Mais je pense qu&#8217;un self.tag = 100 dans le viewDidLoad marche aussi.</p>
<p>Puis voici comment je change de vue : </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p288code37'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p28837"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p288code37"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>ClickMenu<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Vide l'écran de toutes vues, sauf celle de l'écran principale</span>
	NSArray <span style="color: #339933;">*</span>subviews <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">view</span> superview<span style="color: #009900;">&#93;</span> subviews<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	UIView <span style="color: #339933;">*</span>view<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>view in subviews<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Le tag 100 correspond à la vue &quot;Menu Principale&quot;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>view.<span style="color: #202020;">tag</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #009900;">&#91;</span>view removeFromSuperview<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// Définit la vue courante et le gestionnaire d'évènement de MaVueSuivante</span>
	MaVueSuivante<span style="color: #339933;">*</span>myView <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>MaVueSuivantealloc<span style="color: #009900;">&#93;</span> initWithNibName<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;MaVueSuivanteNib&quot;</span> bundle<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>NSBundle mainBundle<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	myView.<span style="color: #202020;">delegate</span> <span style="color: #339933;">=</span> self<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Recupère le singleton de l'application courante</span>
	MonProjetAppDelegate <span style="color: #339933;">*</span>app <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Lacoste_0_MonProjetAppDelegate <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>UIApplication sharedApplication<span style="color: #009900;">&#93;</span> delegate<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>app.<span style="color: #202020;">window</span> addSubview<span style="color: #339933;">:</span>myView.<span style="color: #202020;">view</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Désactivation des boutons &quot;cachés&quot; par la nouvelle vue</span>
	btnVue1.<span style="color: #202020;">enabled</span> <span style="color: #339933;">=</span> NO<span style="color: #339933;">;</span>
	btnVue2.<span style="color: #202020;">enabled</span> <span style="color: #339933;">=</span> NO<span style="color: #339933;">;</span>
	btnVue3.<span style="color: #202020;">enabled</span> <span style="color: #339933;">=</span> NO<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Simple non ?</p>
<p>Enfin pour rendre une vue par dessus une autre tout en gardant la vue principal visible j&#8217;utilise la propriété &laquo;&nbsp;bounds&nbsp;&raquo; de la vue à afficher comme ceci :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p288code38'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p28838"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p288code38"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>viewDidLoad
<span style="color: #009900;">&#123;</span>
	view.<span style="color: #202020;">bounds</span> <span style="color: #339933;">=</span> CGRectMake<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">450</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Une hauteur de -30 pixels par rapport à la normal. </span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/iphone/iphone-uiview.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQlite &amp; Air</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-flex-flash/sqlite-air.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-flex-flash/sqlite-air.html#comments</comments>
		<pubDate>Mon, 02 Feb 2009 07:00:52 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Flex Flash Floush]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=215</guid>
		<description><![CDATA[Un peu d&#8217;ça fait pas de mal non ?
Je fais que peu de back admin en ce moment &#8230; j&#8217;écrit quasi pas de requêtes .. vive les ORM (object-relational mapping) .. et j&#8217;occupe mon temps libre à /Flash et mon application de suivi de stats sportives.
Je suis en train d&#8217;écrire une nouvelle version de mon [...]]]></description>
			<content:encoded><![CDATA[<p>Un peu d&#8217;<a class="shal" href=" http://www.oni-ecchi.info/blog/sql/ape-project-mysql.html" title=" APE Project - Mysql">SQL </a>ça fait pas de mal non ?</p>
<p>Je fais que peu de back admin en ce moment &#8230; j&#8217;écrit quasi pas de requêtes .. vive les <a rel="nofollow" href="http://fr.wikipedia.org/wiki/ORM" target="_blank">ORM </a>(<strong>object-relational mapping</strong>) .. et j&#8217;occupe mon temps libre à <a class="shal" href=" http://www.oni-ecchi.info/blog/decouverte-flex-flash/flex-cest-cool.html" title=" Flex c'est cool">Flex</a>/Flash et mon application de suivi de stats sportives.</p>
<p>Je suis en train d&#8217;écrire une nouvelle version de mon application, avec un code plus propre, et surtout multi utilisateur afin que chacun inscrive ses statistiques sportives dans la même application. Je pourrais m&#8217;en sortir en utilisant à mort les <a rel="nofollow" href="http://www.flex-tutorial.fr/category/httpservice/" target="_blank">HTTPService</a>, faire un webservice et site dédié à la cause.. mais bon je n&#8217;ai pas vocation (pour l&#8217;instant) de créer un site pour se montrer le nombril &#8230; et imaginer le nombre de requêtes à traiter &#8230;</p>
<p>En sachant que Air embarque nativement un moteur <a rel="nofollow" href="http://www.sqlite.org/" target="_blank">SQLite</a>, pourquoi ne pas garder sur le poste du client toutes ses stats ? Quitte à faire par la suite un bouton &laquo;&nbsp;synchroniser sur le web&nbsp;&raquo; :) Ca peut le faire non ?</p>
<p><span id="more-215"></span></p>
<h3>I ) Easy mode</h3>
<p>Voyons voir, tapons &laquo;&nbsp;air sqlite&nbsp;&raquo; dans google et regardons un peu l&#8217;existant</p>
<ul>
<li>Rien ne vaut les exemples adobe : <a rel="nofollow" href="http://www.adobe.com/devnet/air/flex/quickstart/simple_sql_database.html" target="_blank">http://www.adobe.com/devnet/air/flex/quickstart/simple_sql_database.html</a></li>
<li>Mais bon, en francais c&#8217;est mieux : <a rel="nofollow" href="http://www.progs.fr/air-sqlite-exemple   " target="_blank">http://www.progs.fr/air-sqlite-exemple</a></li>
</ul>
<p>On se rend compte que le principe est assez simple au final :</p>
<ol>
<li>Je crée un fichier from scratch via la classe File</li>
<li>Je l&#8217;ouvre à travers une SQLConnection</li>
<li>Je crée un SQLStatement à partir de mon objet SQLConnection</li>
<li>J&#8217;exécute ma requête pour obtenir un SQLResult et j&#8217;en extrait les données sous forme de tableau</li>
<li>Simple non ?</li>
</ol>
<p>Mais bon, même si c&#8217;est l&#8217;affaire d&#8217;une quinzaine de ligne, c&#8217;est quand même un peu relou de tout faut tout se retapper à chaque requete .. autant avoir une classe bien sympa qui gère la BDD dans son coin non ?</p>
<h3>II ) Moi, j&#8217;ai la classe</h3>
<p>J&#8217;aime découper mes applications en MVC quand je le peux. Une classe qui gère ma BDD et qui centralise les appels, c&#8217;est cool. On appelle ça le &laquo;&nbsp;Model&nbsp;&raquo; :) Voici, sans prétention, ma chtite classe qui va bien :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code43'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21543"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code" id="p215code43"><pre class="actionscript" style="font-family:monospace;">package bdd
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">SQLConnection</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">SQLResult</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">SQLStatement</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">File</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySqlLite <span style="color: #0066CC;">extends</span> SQLConnection
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> fichier:File;
&nbsp;
		<span style="color: #808080; font-style: italic;">// Pattern Singleton c'est mieux.</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> instance:MySqlLite
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MySqlLite<span style="color: #66cc66;">&#40;</span>access:Singleton<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Initilisation de la base. Création des tables si besoin est.</span>
			init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// Implémentation du singleton.</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:MySqlLite<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>instance == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				instance = <span style="color: #000000; font-weight: bold;">new</span> MySqlLite<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Singleton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> instance;
		<span style="color: #66cc66;">&#125;</span>		
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Autant se créer notre fichier BDD dans le répertoire d'installation de notre Application non ?</span>
			fichier = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>File.<span style="color: #006600;">applicationDirectory</span>.<span style="color: #006600;">nativePath</span> + <span style="color: #ff0000;">&quot;/Sports2009-bdd.bd&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// Si le fichier n'existe pas déjà, on crée nos tables !</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>fichier.<span style="color: #006600;">exists</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>fichier<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> stmt:SQLStatement = <span style="color: #000000; font-weight: bold;">new</span> SQLStatement<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				stmt.<span style="color: #006600;">sqlConnection</span> = <span style="color: #0066CC;">this</span>;
				stmt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;CREATE TABLE performances (id INTEGER PRIMARY KEY AUTOINCREMENT, creation_date DateTime, calorie decimal, kilometre decimal, temps decimal)&quot;</span>;
				<span style="color: #808080; font-style: italic;">// Hop insertion de notre 1er table</span>
				stmt.<span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;	
&nbsp;
				<span style="color: #808080; font-style: italic;">// Notre Statement est chaud bouillant pour créer une deuxième table, soyons fou.</span>
				stmt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;CREATE TABLE utilisateur (id INTEGER PRIMARY KEY AUTOINCREMENT, nom longvarchar, password longvarchar)&quot;</span>;
				stmt.<span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// Le fichier existe, on ouvre notre bdd :)</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>fichier<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// On peut explicitement fermer la bdd ..</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fermer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// Exécutons notre requete SQL et retournons le résultat :)</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> requete<span style="color: #66cc66;">&#40;</span>maRequeteSql:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:SQLResult
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> requete:SQLStatement = <span style="color: #000000; font-weight: bold;">new</span> SQLStatement<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			requete.<span style="color: #006600;">sqlConnection</span> =<span style="color: #0066CC;">this</span>;
			requete.<span style="color: #0066CC;">text</span> = maRequeteSql
			requete.<span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// On récupère le résultat de l'execution</span>
			<span style="color: #000000; font-weight: bold;">var</span> r:SQLResult = <span style="color: #000000; font-weight: bold;">new</span> SQLResult<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>		
&nbsp;
			<span style="color: #808080; font-style: italic;">// ATTENTION on ne peut faire qu'un seul getResult()</span>
			<span style="color: #808080; font-style: italic;">// Pourquoi ? car c'est à usage unique</span>
			<span style="color: #808080; font-style: italic;">// une fois que l'on a demandé des infos &quot;pssshhtt ça disparait !&quot;</span>
			r =  requete.<span style="color: #006600;">getResult</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> r;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Singleton<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Singleton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<h3>Utilisation</h3>
<p>Pour la gestion de mes utilisateurs par exemple, voici ma classe &laquo;&nbsp;Utilisateur&nbsp;&raquo; (Waahou je suis original) qui me sert à l&#8217;insertion et la connexion, etc d&#8217;un de mes gugus. Elle est vraiment basique, mais ça marche ;)</p>
<p>On reste encore dans le &laquo;&nbsp;Model&nbsp;&raquo; :)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code44'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21544"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code" id="p215code44"><pre class="actionscript" style="font-family:monospace;">package users
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> bdd.<span style="color: #006600;">MySqlLite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">SQLResult</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">SQLStatement</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Utilisateur <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Object</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">password</span>:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Utilisateur<span style="color: #66cc66;">&#40;</span>nom:<span style="color: #0066CC;">String</span>,pass:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">setName</span><span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">setPassword</span><span style="color: #66cc66;">&#40;</span>pass<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">name</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPassword<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">password</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setName<span style="color: #66cc66;">&#40;</span>nom:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">name</span>= nom;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setPassword<span style="color: #66cc66;">&#40;</span>pass:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">password</span> = pass;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// Test voir si le gugus existe</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> existe<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> test:SQLResult = <span style="color: #000000; font-weight: bold;">new</span> SQLResult<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			test = MySqlLite.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">requete</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SELECT * from utilisateur WHERE nom='&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">name</span> +<span style="color: #ff0000;">&quot;' and password='&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">password</span> +<span style="color: #ff0000;">&quot;' &quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> test.<span style="color: #0066CC;">data</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// Inscription du gugus</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> inscription<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>existe<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> test:SQLResult = <span style="color: #000000; font-weight: bold;">new</span> SQLResult<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				test = MySqlLite.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">requete</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;INSERT INTO utilisateur (nom,password) VALUES ('&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">name</span> +<span style="color: #ff0000;">&quot;','&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">password</span> +<span style="color: #ff0000;">&quot;') &quot;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Et le petit contrôleur qui va bien, extrait de mon code :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code45'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21545"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p215code45"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TestConnexion<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:ConnexionEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> user:Utilisateur = <span style="color: #000000; font-weight: bold;">new</span> Utilisateur<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">sLogin</span>,<span style="color: #0066CC;">e</span>.<span style="color: #006600;">sPassword</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>user.<span style="color: #006600;">existe</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		pannelConnexion.<span style="color: #006600;">currentState</span> = <span style="color: #ff0000;">&quot;OK&quot;</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">currentState</span> = <span style="color: #ff0000;">&quot;Dashboard&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		pannelConnexion.<span style="color: #006600;">currentState</span> = <span style="color: #ff0000;">&quot;Erreur&quot;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Inscription<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:ConnexionEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> user:Utilisateur = <span style="color: #000000; font-weight: bold;">new</span> Utilisateur<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">sLogin</span>,<span style="color: #0066CC;">e</span>.<span style="color: #006600;">sPassword</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>user.<span style="color: #006600;">inscription</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;je me suis bien inscrit&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;j'existe déjà ...&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Vous notez que j&#8217;ai un évènement personnalisé qui contient le login &amp; le password à tester. Voici son code pour ceux que ça intéresse, y a rien de spécial, c&#8217;est tout basique :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code46'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21546"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p215code46"><pre class="actionscript" style="font-family:monospace;">package Event
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConnexionEvent <span style="color: #0066CC;">extends</span> Event
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sLogin:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sPassword:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConnexionEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>,login:<span style="color: #0066CC;">String</span>,<span style="color: #0066CC;">password</span>:<span style="color: #0066CC;">String</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;
			sLogin = login;
			sPassword = <span style="color: #0066CC;">password</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Voilà, vous avez là un exemple très simpliste d&#8217;utilisation de SQLite dans Air. Pour tout dire, je ne suis pas encore aller très loin avec :)</p>
<p>A vous de jouer !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-flex-flash/sqlite-air.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
