{"id":1401,"date":"2014-08-18T11:25:12","date_gmt":"2014-08-18T15:25:12","guid":{"rendered":"http:\/\/tim.cstj.qc.ca\/cours\/xcode\/wp\/?page_id=1401"},"modified":"2014-08-18T11:25:12","modified_gmt":"2014-08-18T15:25:12","slug":"swift-labo-st-hub","status":"publish","type":"page","link":"https:\/\/ve2cuy.com\/xcode\/swift-labo-st-hub\/","title":{"rendered":"Swift &#8211; labo St-Hub"},"content":{"rendered":"<h1>Directives<\/h1>\n<ul>\n<li>Programmer une application iPhone qui permet la\u00a0saisie d&rsquo;une commande chez St-Hubert.<\/li>\n<li>Les \u00e9l\u00e9ments visuels devront se positionner correctement en fonction de la taille de l&rsquo;\u00e9cran (utilisation de marges).<\/li>\n<li>Le clavier devra disparaitre suite \u00e0 un &lsquo;enter&rsquo; dans le champ &lsquo;Quantit\u00e9&rsquo; (d\u00e9l\u00e9gation)<\/li>\n<li>Le total de la commande sera calcul\u00e9 ( quant * prix + taxes) et affich\u00e9 \u00e0 l&rsquo;\u00e9cran<\/li>\n<\/ul>\n<hr \/>\n<p>&nbsp;<\/p>\n<h1>\u00c9tape 1 &#8211; \u00c9laboration de l&rsquo;interface utilisateur<\/h1>\n<p><span style=\"color: #ff0000;\"><strong>Action<\/strong><\/span>: Programmez l&rsquo;interface utilisateur.<br \/>\nNote: Il faut reproduire le design suivant et s&rsquo;assurer qu&rsquo;il s&rsquo;affiche correctement sur un \u00e9cran de 3.5 et 4 pouces.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1402\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/st-hub.01.png\" alt=\"st-hub.01\" width=\"569\" height=\"343\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1403\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/st-hub.02.png\" alt=\"st-hub.02\" width=\"479\" height=\"343\" \/><br \/>\nVoici les \u00e9l\u00e9ments visuels:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1408\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/labo-st-hub-image01.png\" alt=\"labo-st-hub-image01\" width=\"424\" height=\"308\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1409\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/labo-st-hub-image02.png\" alt=\"labo-st-hub-image02\" width=\"136\" height=\"34\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1410\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/labo-st-hub-image03.png\" alt=\"labo-st-hub-image03\" width=\"118\" height=\"129\" \/><br \/>\nAinsi que la structure de la sc\u00e8ne:<br \/>\nNote: Il faut cr\u00e9er un &lsquo;group&rsquo; pour les images.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1413\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/st-hub_08.png\" alt=\"st-hub_08\" width=\"1151\" height=\"415\" \/><\/p>\n<hr \/>\n<h1>Partie 2 &#8211; R\u00e9action suite au bouton &lsquo;Commander&rsquo;<\/h1>\n<p><span style=\"color: #ff0000;\"><strong>Action<\/strong><\/span> &#8211; Localisez, dans la section &lsquo;<a href=\"les-copiercoller-swift\/\">Recettes<\/a>&lsquo;, le code qui permet d&rsquo;afficher une boite d&rsquo;alerte et ins\u00e9rez le dans le projet.<br \/>\nNote: \u00a0La boite d&rsquo;alerte doit s&rsquo;afficher suite \u00e0 un clic sur le bouton &lsquo;Commander&rsquo;. \u00a0Indice: Lien de type &lsquo;IBAction&rsquo;.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1404\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/st-hub.03.png\" alt=\"st-hub.03\" width=\"481\" height=\"342\" \/><br \/>\nAction: \u00a0Testez l&rsquo;application, avec le simulateur, en mode &lsquo;iPhone 4s&rsquo; puis en mode &lsquo;iPhone 5s&rsquo;<\/p>\n<hr \/>\n<h1>Partie 3 &#8211; Saisir une quantit\u00e9 et calculer le prix total<\/h1>\n<p>&nbsp;<br \/>\n<span style=\"color: #ff0000;\"><strong>Action<\/strong><\/span> &#8211; Ajoutez les \u00e9l\u00e9ments &lsquo;quantit\u00e9&rsquo; et &lsquo;total&rsquo; \u00e0 l&rsquo;\u00e9cran de l&rsquo;application<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1406\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/st-hub.05.png\" alt=\"st-hub.05\" width=\"760\" height=\"420\" \/><br \/>\n<span style=\"color: #ff0000;\"><strong>Action<\/strong><\/span> &#8211; D\u00e9finissez des liens &lsquo;IBOutlet&rsquo; sur ces deux \u00e9l\u00e9ments<br \/>\n<span style=\"color: #ff0000;\"><strong>Action<\/strong><\/span> &#8211; Copier la <a href=\"swift-signature-des-methodes-de-delegation-protocole\">signature<\/a> de la m\u00e9thode &lsquo;textFieldShouldReturn&rsquo; dans le projet et renseigner la d\u00e9l\u00e9gation sur le champ de saisie de la quantit\u00e9.<br \/>\n<span style=\"color: #ff0000;\"><strong>Action<\/strong><\/span> &#8211; Dans la m\u00e9thode &lsquo;textFieldShouldReturn&rsquo;, programmez le calcul du total et affichez le \u00e0 l&rsquo;\u00e9cran.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1407\" src=\"\/xcode\/wp-content\/uploads\/2014\/08\/st-hub.06.png\" alt=\"st-hub.06\" width=\"569\" height=\"343\" \/><br \/>\nIndices<\/p>\n<pre class=\"lang:swift decode:true\">\/\/ Masquer le clavier suite \u00e0 un 'enter'\nfunc textFieldShouldReturn(textField:UITextField!) -&gt; Bool{\n  textField.resignFirstResponder()\n  return true\n}\n<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"lang:swift decode:true \">\/\/ Calcul du total\nlet prix:Float = 11.20      \/\/ Prix par item\nvar _total = prix * Float(Int(quant.text!)!)  \/\/ Assumer que text et Int() ne retourneront pas 'nil'\n_total = _total * 1.05      \/\/ Ajouter TPS\n_total = _total * 1.09975   \/\/ Ajouter TVQ - Note: La TVQ est calcul\u00e9e sur le total + TPS\n\/\/ Afficher le total en format 99.99$\n... = NSString(format:\"%2.2f$\", _total)\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Directives Programmer une application iPhone qui permet la\u00a0saisie d&rsquo;une commande chez St-Hubert. Les \u00e9l\u00e9ments visuels devront se positionner correctement en fonction de la taille de l&rsquo;\u00e9cran (utilisation de marges). Le clavier devra disparaitre suite \u00e0 un &lsquo;enter&rsquo; dans le champ &lsquo;Quantit\u00e9&rsquo; (d\u00e9l\u00e9gation) Le total de la commande sera calcul\u00e9 ( quant * prix + taxes) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1401","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/pages\/1401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/comments?post=1401"}],"version-history":[{"count":0,"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/pages\/1401\/revisions"}],"wp:attachment":[{"href":"https:\/\/ve2cuy.com\/xcode\/wp-json\/wp\/v2\/media?parent=1401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}