tag:blogger.com,1999:blog-39460995681076553022024-03-09T18:46:50.669-08:00iCodingiPhone app Development Tutorials . .RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-3946099568107655302.post-79441765030258368122013-04-02T01:25:00.003-07:002013-04-03T00:46:30.768-07:00CoreData in iPhone Complete Tutorial (Basic)<div dir="ltr" style="text-align: left;" trbidi="on">
<b style="background-color: white; color: #222222; font-family: Helvetica; font-size: 12px; line-height: 16px;">Hola,, iDevelopers,, </b><span style="background-color: white; color: #4f7a28; font-family: Helvetica; font-size: 12px; line-height: 16px;"><b>RDC</b></span><b style="background-color: white; color: #222222; font-family: Helvetica; font-size: 12px; line-height: 16px;"> is here</b><br />
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Enjoying <span style="color: #674ea7;">Punjabi</span> Pop "<span style="font-family: Arial; font-size: 13px;"><b>Sadi Gali Aaja Sanu..</b></span>" and I am going to write one more Article</div>
<div style="font-family: Helvetica; font-size: 12px;">
about one of the important key feature in iOS.<br />
<br />
Because Now-days Core Data is widely using in iPhone Applications<br />
Shortly I'll post complete theory article on Core Data here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
How to use Core Data in our iPhone application with Insert, Select, Search and Delete operation programmatically?</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjguU5LvX4_5WF7ftz42zd5xShCb3O_JP8B5yMjw3Ym1yXZYGhqL2lkbgzsbZiXQO3g98zBruAeIEBSlye8DKhn6gaDH8lJElCBlfY6CZQLbx473LEiQ_QEGco6GTJUTCWdLhGU1ATP4VCa/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjguU5LvX4_5WF7ftz42zd5xShCb3O_JP8B5yMjw3Ym1yXZYGhqL2lkbgzsbZiXQO3g98zBruAeIEBSlye8DKhn6gaDH8lJElCBlfY6CZQLbx473LEiQ_QEGco6GTJUTCWdLhGU1ATP4VCa/s1600/Screen+0.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #7b219f; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Before starting You may like to know our Database details</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span style="color: #008400;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CoreData Model Name : </span><b>contacts.momd</b> |</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;">|</span><span class="Apple-tab-span" style="white-space: pre;"> </span>CoreData Database File Name : <span style="color: black;"><b>contacts.sqlite </b>|</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;">|</span><span class="Apple-tab-span" style="white-space: pre;"> </span>CoreData Entity(Table) Name : <span style="color: black;"><b>Contacts</b> |</span></div>
<div style="font-family: Menlo; font-size: 11px;">
| <span style="color: #4f7a28;">Table Columns Name : </span>NAME, ADDRESS, PHONE |</div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6 , Xcode 4.6, and MAC OS X Lion 10.8.1</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>CoreDataDemo<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQuwjZDHuB90ggLcJDehxttq0zoKAeX8jvUq7L8mgUMKhUusT-pRa0JP6CR7SG6_3LFb-9Db-3aQMutJb9smLsil60ch5l-_TmZgakD3vvhF-wHCVxc_H5lqwWb0rTvf-0VgleYZbKDu6s/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="264" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQuwjZDHuB90ggLcJDehxttq0zoKAeX8jvUq7L8mgUMKhUusT-pRa0JP6CR7SG6_3LFb-9Db-3aQMutJb9smLsil60ch5l-_TmZgakD3vvhF-wHCVxc_H5lqwWb0rTvf-0VgleYZbKDu6s/s320/Screen+2.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Add Extra Frameworks/ Lib and Create required Files)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
to use the Core Data we need to add <span style="color: #c4bc00;">CoreData.framework</span><span style="color: #669c35;"> </span>to our Project.</div>
<div style="font-family: Helvetica; font-size: 12px;">
procedure is simple just follow the below steps..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. select Project (Blue Icon) go to --> Build Phased --> <b>Link Binary With Libraries</b> option --> click (+) and you will get popup window, so search for "<span style="color: #0056d6;">coredata</span>", -->select <span style="color: #c4bc00;">CoreData.framework</span><span style="color: #669c35;"> </span>--> click to add.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwq7rQMlMnPggNIoP6JdBuvpQYZhyphenhyphenT0zzav5fkUjEb11-A35O-rOR3aoqC84wwzIZPzHLjWSoGLntftzuF7cfBLyp9LEBdZSkveyDpxeHnZfLwqPNbXqGjQA3JF2szU4XoFF7lcmFogON4/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwq7rQMlMnPggNIoP6JdBuvpQYZhyphenhyphenT0zzav5fkUjEb11-A35O-rOR3aoqC84wwzIZPzHLjWSoGLntftzuF7cfBLyp9LEBdZSkveyDpxeHnZfLwqPNbXqGjQA3JF2szU4XoFF7lcmFogON4/s320/Screen+3.png" width="286" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
after adding successful you can see <span style="color: #c4bc00;">CoreData.framework</span> added to our project, drag it to the Frameworks folder.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Import CoreData header file in .pch)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Update .pch file (CoreDataDemo-Prefix.pch) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
here I would like to suggest you, when we need any lib/framework classes in our application's class then we need to import particular relevant header file, but if we will import in <b>.pch file</b> then it will be available in whole application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Open <b>CoreDataDemo-Prefix.pch</b> file in folder named "Supporting Files" in default project structure.</div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Here we can see by default already to classes added (UIKit and Foundation), below to these two file just add core data header file this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><CoreData/CoreData.h></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>CoreDataDemo-Prefix.pch</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Prefix header for all source files of the 'CoreDataDemo' target in the 'CoreDataDemo' project</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Availability.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#ifndef __IPHONE_4_0</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#warning "This project uses features only available in iOS SDK 4.0 and later."</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#endif</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#ifdef __OBJC__</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;"> #import </span><UIKit/UIKit.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;"> #import </span><Foundation/Foundation.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;"> #import </span><CoreData/CoreData.h></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#endif</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
Good!! now save it and go ahead --></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Create Core Data model file to store entity)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Now We will Create one "contacts.xcdatamodeld" file</b></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Right click on project (as shown in picture) --> New File </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiye4ss15FHC23zoM3jr9aAKXz0NLOftIyWtXolJbtXkoEnUGtixVvG7-xuNAgycNTNQwsiCBpfDSnf2zyvpwSUaaHa8g0uJlXllTj_2CeKB3hcAgR0GnJubVX3XaGmsu6QDJDjdLwTc_g4/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiye4ss15FHC23zoM3jr9aAKXz0NLOftIyWtXolJbtXkoEnUGtixVvG7-xuNAgycNTNQwsiCBpfDSnf2zyvpwSUaaHa8g0uJlXllTj_2CeKB3hcAgR0GnJubVX3XaGmsu6QDJDjdLwTc_g4/s320/Screen+5.png" width="276" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select <b>Data Model</b> Template (in iOS + Core Data option) --> Go Next</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZcLebea57YjUjfO0GG1pH-WEMvj8UPASlHh4Vm-yuT-dVbOQ414cGWEQBa-LuO2zqPVWdT6iwYF_1sWNNwdUrx83aVOe6B0tvcq02vhvn4OR0jfYRrPA24BhyphenhyphenlRecWbblOY0u5ZvGh-XB/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZcLebea57YjUjfO0GG1pH-WEMvj8UPASlHh4Vm-yuT-dVbOQ414cGWEQBa-LuO2zqPVWdT6iwYF_1sWNNwdUrx83aVOe6B0tvcq02vhvn4OR0jfYRrPA24BhyphenhyphenlRecWbblOY0u5ZvGh-XB/s320/Screen+6.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Give the name as "Contacts" --> Create</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju01IJWTPdfWSWjaEdE4MnnK_K8UvyFcDuNrpDmToUq49BeqwoMr0fkdch1F6cYmMKNoXjVvdP9q9kZ5IeFj3DklGWJpVV_g5ckiCVjoqH6KndSKIKz72PsM9HWkz1DCtHPf-GWemSjB8Q/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="224" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju01IJWTPdfWSWjaEdE4MnnK_K8UvyFcDuNrpDmToUq49BeqwoMr0fkdch1F6cYmMKNoXjVvdP9q9kZ5IeFj3DklGWJpVV_g5ckiCVjoqH6KndSKIKz72PsM9HWkz1DCtHPf-GWemSjB8Q/s320/Screen+7.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see <span style="color: #4f7a28;"><b>contacts.xcdatamodeld </b></span>file is added to our project.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Create Entity, Attributes in contacts.xcdatamodeld file</b></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Create Entity</b></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Open Contacts.xcdatamodeld file, we can see blank database schema graph here and no entity so far.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ_E8j3P3vK8-ox2Myzdurmm8uCNH4nk5GGytlGzneIe3qU_PK7rMStaeB2Q2h_iHIEGE3I9dtYTAQwWCYgROa8Ma7UK4YBJPD_RFO_mBG0zeQRmbo1naaLTER7YwQJGZ3ptHC8RDWmlwl/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ_E8j3P3vK8-ox2Myzdurmm8uCNH4nk5GGytlGzneIe3qU_PK7rMStaeB2Q2h_iHIEGE3I9dtYTAQwWCYgROa8Ma7UK4YBJPD_RFO_mBG0zeQRmbo1naaLTER7YwQJGZ3ptHC8RDWmlwl/s320/Screen+8.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Click on Add Entity (+) button (it's on Bottom Left side) to create new entity-->Give the name "Contacts"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj37_KdxsDyAeM3eNmFjxxc0wZ_1nXpyydwAjn40fAQXNgrnLWBVOx4rR9vDyjxrWtDnR-4Rc9s2djL8B1xjH7A3GDgJcX723HONHrQOruMcf5ZvYtPISDoWEdwkUtKEPbj7U2bUoW3XtEo/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj37_KdxsDyAeM3eNmFjxxc0wZ_1nXpyydwAjn40fAQXNgrnLWBVOx4rR9vDyjxrWtDnR-4Rc9s2djL8B1xjH7A3GDgJcX723HONHrQOruMcf5ZvYtPISDoWEdwkUtKEPbj7U2bUoW3XtEo/s320/Screen+9.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Create Attributes</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. select Entity (Contacts) --> Click on Add Attribute (+) button (it's on Bottom Right side) to create new attribute-->double click on it, change <span style="color: #be38f3;">Attribute = name</span> and <span style="color: #be38f3;">Type = string</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. do the same and create two more attribute <span style="color: #be38f3;">phone</span> and <span style="color: #be38f3;">address</span>.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgonwyO3DwmARjwGxNZiAc8XFn11bV_8QbZmJf1IWHOdMaIVRZlaLBK4oBAE4yTHUxe_pzizVv9QRO0j9-eVXlXcQZl63h1dSP40VHopoa0p-03RVSpQYP7gfT4gYgmLLTniN8R21GYs1jf/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgonwyO3DwmARjwGxNZiAc8XFn11bV_8QbZmJf1IWHOdMaIVRZlaLBK4oBAE4yTHUxe_pzizVv9QRO0j9-eVXlXcQZl63h1dSP40VHopoa0p-03RVSpQYP7gfT4gYgmLLTniN8R21GYs1jf/s320/Screen+10.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Good!! save the file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - V (Create Object Model class for Entity )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Object Model Class (Contacts) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Now We will create model class for this entity "Contacts"</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Right click on project --> New File</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select<b> NSManagedObjectsubclass</b> Template (in iOS + Core Data option) --> Go Next</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjozKMWos3BbhrrawT7Pj4DLNw2U2ehmHm0kn8WQ6qiy4MA60olb439tjIoLZvbkwZKmY7lX7ajE38wPUK7h9DYMLK-5awIpLgUUgHD-aHcz9ZLGeq2lXAEyNz0RLp_l2BnYC3bFZjRPuZm/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjozKMWos3BbhrrawT7Pj4DLNw2U2ehmHm0kn8WQ6qiy4MA60olb439tjIoLZvbkwZKmY7lX7ajE38wPUK7h9DYMLK-5awIpLgUUgHD-aHcz9ZLGeq2lXAEyNz0RLp_l2BnYC3bFZjRPuZm/s320/Screen+11.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. select the entity <span style="color: #4f7a28;"><b>Contacts </b></span>and go to Next.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI4xig2oY8CRmWHEHMftfPQfBugfpzrQEcMG-Rnpo6zPKvUi2nRHl32sXxXcVQp1gBipLI3Op-cMSZvONDtzCb_2iR8JgxiqrJ13pMrQZZpWaM80zvLgOsmQv5sLTvfFj-L9cmUv6SLxZi/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI4xig2oY8CRmWHEHMftfPQfBugfpzrQEcMG-Rnpo6zPKvUi2nRHl32sXxXcVQp1gBipLI3Op-cMSZvONDtzCb_2iR8JgxiqrJ13pMrQZZpWaM80zvLgOsmQv5sLTvfFj-L9cmUv6SLxZi/s320/Screen+12.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see <span style="color: #4f7a28;"><b>contacts.h </b></span>and<span style="color: #4f7a28;"><b> contacts.m </b></span>files are added to our project.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>Contacts.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Contacts.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 29/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><CoreData/CoreData.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> Contacts : </span>NSManagedObject</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> * name;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> * phone;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> * address;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
also Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>Contacts.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Contacts.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 29/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"Contacts.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> Contacts</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@dynamic<span style="color: black;"> name;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@dynamic<span style="color: black;"> phone;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@dynamic</span> address;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - V (Create Helper Class to handle all the Core Data Tasks )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ HELPER Class (CoreDataHelper) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Now We will create two Important Classes </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Here is the Heart of Application</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We will create Helper class for Core Data</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
CoreDataHelper.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
CoreDataHelper.m</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Where we will mange complete core data life cycle, also we are going to add method for making various operation on Core Data</div>
<div style="font-family: Helvetica; font-size: 12px;">
such as INSERT, SEARCH,DELETE,VIEW ALL etc.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay tune and try to get the rhythm of this music … oops!! it would be Core data :)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let's follow to the footprints..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Right click on project --> New File</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select<b> Objective-C class</b> Template (in iOS + Cocoa Touch) --> Go Next</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s320/Screen+7.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. put the details as given below</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class = <b>CoreDataHelper</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Subclass of = <b>NSObject</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #4f7a28;"><b> </b></span>and go to Next.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb-8W1k1te8NB_GgdeSTnxeADda3MvdvnDZY2x5jrOVq_FqWFh00X-govkkYmPAR2G9l8LDLUkhfBD_RBddt2cKlz1akA8YI2m2KijNq7XaMqfA2FcICB2j5WnRHWOW_4VqUnKq88EpoZh/s1600/Screen+14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="264" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb-8W1k1te8NB_GgdeSTnxeADda3MvdvnDZY2x5jrOVq_FqWFh00X-govkkYmPAR2G9l8LDLUkhfBD_RBddt2cKlz1akA8YI2m2KijNq7XaMqfA2FcICB2j5WnRHWOW_4VqUnKq88EpoZh/s320/Screen+14.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see <span style="color: #4f7a28;"><b>CoreDataHelper.h </b></span>and<span style="color: #4f7a28;"><b> CoreDataHelper.m </b></span>files are added to our project.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, this time our project structure is look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin6wQpaHQechEN3nFbvDKkp9oVxAvoVx6FRwA6egIUPh4WVYk3NtgbRItYbM5M1HB-jlIMxlM4VQCh1_W9Xsm0K0v97eCs_HXLm7cZ8AWFZuu62OxaPC74_0Y8FGjegigvPgQxaHNjMISa/s1600/Screen+15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin6wQpaHQechEN3nFbvDKkp9oVxAvoVx6FRwA6egIUPh4WVYk3NtgbRItYbM5M1HB-jlIMxlM4VQCh1_W9Xsm0K0v97eCs_HXLm7cZ8AWFZuu62OxaPC74_0Y8FGjegigvPgQxaHNjMISa/s1600/Screen+15.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #e32400;"><b>Note : </b></span>You may have question here As I have put all the files in MVC manner, </div>
<div style="font-family: Helvetica; font-size: 12px;">
If you wish to do that, please! right click on project and create New Groups and give name as Models, Views, Controllers,CoreData Helper.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then just drag the files in relative folder groups as shown in screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<span style="color: black;">4. open </span><b>CoreDataHelper.h </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
5. add three most important instance variables with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property </span>of Core Data classes</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSManagedObjectContext</span><span style="color: black;"> *context;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSManagedObjectModel</span><span style="color: black;"> *objectModel;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span><span style="color: black;"> (</span><span style="color: #bb2ca2;">nonatomic</span><span style="color: black;">, </span><span style="color: #bb2ca2;">retain</span><span style="color: black;">) </span>NSPersistentStoreCoordinator<span style="color: black;"> *coordinator;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
6. declare static init method to initialise the Helper class</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">CoreDataHelper</span> *) initCoreDataHelper;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
7. declare all the require instance method to manage Core Data life cycle.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) initializeContext;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getApplicationDocumentsDirectoryPath;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSManagedObjectModel</span> *) initilizeManagedObjectModel;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSPersistentStoreCoordinator</span> *) initilizeManagedPersistentStoreCoordinator;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) saveCurrentContext;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
8. and finally declare method to handle all Core Data operations like Insert and Delete data.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
/methods to perform database operations</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName :(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSManagedObject</span> *) searchContactInfoByName :(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>CoreDataHelper.h</b></span> file look like</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataHelper.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 01/04/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><CoreData/CoreData.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> CoreDataHelper : <span style="color: #703daa;">NSObject</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSManagedObjectContext</span><span style="color: black;"> *context;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSManagedObjectModel</span><span style="color: black;"> *objectModel;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span><span style="color: black;"> (</span><span style="color: #bb2ca2;">nonatomic</span><span style="color: black;">, </span><span style="color: #bb2ca2;">retain</span><span style="color: black;">) </span>NSPersistentStoreCoordinator<span style="color: black;"> *coordinator;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//mehthods to manage core data life cycle</div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">CoreDataHelper</span> *) initCoreDataHelper;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) initializeContext;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getApplicationDocumentsDirectoryPath;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSManagedObjectModel</span> *) initilizeManagedObjectModel;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSPersistentStoreCoordinator</span> *) initilizeManagedPersistentStoreCoordinator;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) saveCurrentContext;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//methods to perform database operations</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName :(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSManagedObject</span> *) searchContactInfoByName :(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great going!! just save the file and move to it's implementation file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<span style="color: black;">9. open </span><b>CoreDataHelper.m</b><span style="color: black;"> file </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
10. add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@synthesize</span> (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> context;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> objectModel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> coordinator;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
11. create static instance of CoreDataHelper class.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #4f8187;">CoreDataHelper</span> *coreDataHelper;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
12. update the <b>initCoreDataHelper</b> method to <span style="color: #be38f3;">initialise this class and Current Context</span>.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">CoreDataHelper</span> *) initCoreDataHelper{ </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">coreDataHelper</span> == <span style="color: #bb2ca2;">nil</span>) { </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>coreDataHelper<span style="color: black;"> = [[</span>CoreDataHelper<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">coreDataHelper</span> <span style="color: #31595d;">initializeContext</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>coreDataHelper<span style="color: black;">; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
See don't worry we are going to provide the body for "initializeContext"<span style="font-family: Menlo; font-size: 11px;"> </span>method, used here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
13. now update the <b>getApplicationDocumentsDirectoryPath</b> method's body to get path</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getApplicationDocumentsDirectoryPath{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSArray</span><span style="color: black;"> *paths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *basePath = ([paths <span style="color: #3d1d81;">count</span>] > <span style="color: #272ad8;">0</span>) ? [paths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>] : <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> basePath;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
14. update <b>initilizeManagedObjectModel</b> to init the managed object model</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSManagedObjectModel</span> *) initilizeManagedObjectModel{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">objectModel</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>objectModel<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSURL</span><span style="color: black;"> *modelURL = [[</span><span style="color: #703daa;">NSBundle</span><span style="color: black;"> </span>mainBundle<span style="color: black;">] </span>URLForResource<span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span>withExtension<span style="color: black;">:</span><span style="color: #d12f1b;">@"momd"</span><span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">objectModel</span><span style="color: black;"> = [[</span><span style="color: #703daa;">NSManagedObjectModel</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithContentsOfURL<span style="color: black;">:modelURL];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>objectModel<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
15. here is time to create database using all gathered info.</div>
<div style="font-family: Helvetica; font-size: 12px;">
so provide the body for <b>initilizeManagedPersistentStoreCoordinator</b><span style="font-family: Menlo; font-size: 11px;"> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSPersistentStoreCoordinator</span> *) initilizeManagedPersistentStoreCoordinator{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">coordinator</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>coordinator<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSURL</span><span style="color: black;"> *storeUrl = [</span><span style="color: #703daa;">NSURL</span><span style="color: black;"> </span>fileURLWithPath<span style="color: black;">:[[</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span><span style="color: #31595d;">getApplicationDocumentsDirectoryPath</span><span style="color: black;">]</span>stringByAppendingPathComponent<span style="color: black;">: </span><span style="color: #d12f1b;">@"Contacts.sqlite"</span><span style="color: black;">]]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">coordinator</span><span style="color: black;"> = [[</span>NSPersistentStoreCoordinator<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">initWithManagedObjectModel</span>:[<span style="color: #bb2ca2;">self</span> <span style="color: #31595d;">initilizeManagedObjectModel</span>]];</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> (![</span><span style="color: #4f8187;">coordinator</span><span style="color: black;"> </span>addPersistentStoreWithType<span style="color: black;">:</span><span style="color: #703daa;">NSSQLiteStoreType</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">configuration</span>:<span style="color: #bb2ca2;">nil</span> <span style="color: #3d1d81;">URL</span>:storeUrl <span style="color: #3d1d81;">options</span>:<span style="color: #bb2ca2;">nil</span> <span style="color: #3d1d81;">error</span>:&error]) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Unresolved error %@, %@"</span>, error, [error <span style="color: #3d1d81;">userInfo</span>]);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">abort</span>();</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>coordinator<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
16. yeah! as I promised now update the body for <b>initializeContext</b><span style="font-family: Menlo; font-size: 11px;"> </span>method here, to init the current context of core data</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) initializeContext{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">context</span> == <span style="color: #bb2ca2;">nil</span>) { </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSPersistentStoreCoordinator</span><span style="color: black;"> *acoordinator = [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>initilizeManagedPersistentStoreCoordinator<span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">context</span><span style="color: black;"> = [[</span>NSManagedObjectContext<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">setPersistentStoreCoordinator</span>:acoordinator]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
17. final method for Core Data life cycle to save the current context when app is going to… hell .. </div>
<div style="color: #669c35; font-family: Helvetica; font-size: 12px;">
<span style="color: black;">Okay!! </span>This method we will use in App Delegate class to store our application core data state<span style="color: black;"> when user quite app etc.</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) saveCurrentContext{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">context</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">hasChanges</span>] && ![<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">save</span>:&error]) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Unresolved error %@, %@"</span>, error, [error <span style="color: #3d1d81;">userInfo</span>]);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">abort</span>();</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//now update the methods to perform database operations</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
18. here we have Four method to hand INSERT, SELECT ALL, SEARCH, DELETE operations on Core Data</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
</div>
<div style="min-height: 14px;">
<br /></div>
<div style="color: #9929bd;">
All below steps we need to follow to work with Core Data so keep in mind these things</div>
<div style="min-height: 14px;">
<br /></div>
<span style="font-size: x-small;"> --------------------------------------------------------------------------------------</span><br />
<span style="font-size: x-small;">| Get Current Context (NSManagedObjectContext) |</span><br />
<span style="font-size: x-small;">| Init Fetch Request (optional)<span class="Apple-tab-span" style="white-space: pre;"> </span> |<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: x-small;">| Get Entity Description<span class="Apple-tab-span" style="white-space: pre;"> </span> |</span><br />
<span style="font-size: x-small;">| Add Entity Description to Request<span class="Apple-tab-span" style="white-space: pre;"> </span> |</span><br />
<span style="font-size: x-small;">| Create Predicate (Optional) |</span><br />
<span style="font-size: x-small;">| Add Predicate to Request<span class="Apple-tab-span" style="white-space: pre;"> </span> |</span><br />
<span style="font-size: x-small;">| Execute Fetch Request |</span><br />
<span style="font-size: x-small;">| Use Results |</span><br />
<span style="font-size: x-small;">| Save Context (optional) |</span><br />
<span style="font-size: x-small;">---------------------------------------------------------------------------------------</span><br />
<br />
<div style="color: #9929bd; font-family: Menlo; font-size: 11px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
18.1 Insert contact method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName:(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO{ </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSManagedObject</span> *newContact; </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> newContact = [</span><span style="color: #703daa;">NSEntityDescription</span><span style="color: black;"> </span>insertNewObjectForEntityForName<span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span>inManagedObjectContext<span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[newContact <span style="color: #3d1d81;">setValue</span>:name <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[newContact <span style="color: #3d1d81;">setValue</span>:address <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[newContact <span style="color: #3d1d81;">setValue</span>:phoneNO <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"phone"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">save</span>:&error]) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Contact saved"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Error occured while saving"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
18.2 select all the stored contact method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSFetchRequest</span> *fetchRequest = [[<span style="color: #703daa;">NSFetchRequest</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSEntityDescription<span style="color: black;"> *entity = [</span>NSEntityDescription<span style="color: black;"> </span><span style="color: #3d1d81;">entityForName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span><span style="color: #3d1d81;">inManagedObjectContext</span><span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setEntity</span>:entity];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *objects = [<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">executeFetchRequest</span>:fetchRequest <span style="color: #3d1d81;">error</span>:&error]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([objects <span style="color: #3d1d81;">count</span>]><span style="color: #272ad8;">0</span>) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span> (<span style="color: #703daa;">NSManagedObject</span> *aContact <span style="color: #bb2ca2;">in</span> objects) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"name=%@, address=%@, phone=%@"<span style="color: black;">,[aContact </span><span style="color: #3d1d81;">valueForKey</span><span style="color: black;">:</span>@"name"<span style="color: black;">],[aContact </span><span style="color: #3d1d81;">valueForKey</span><span style="color: black;">:</span>@"address"<span style="color: black;">],[aContact </span><span style="color: #3d1d81;">valueForKey</span><span style="color: black;">:</span>@"phone"<span style="color: black;">]);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"no matches found"</span>); </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
18.3 search particular contact info by Name and returns object</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSManagedObject</span> *) searchContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSFetchRequest</span> *fetchRequest = [[<span style="color: #703daa;">NSFetchRequest</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSEntityDescription<span style="color: black;"> *entity = [</span>NSEntityDescription<span style="color: black;"> </span><span style="color: #3d1d81;">entityForName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span><span style="color: #3d1d81;">inManagedObjectContext</span><span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setEntity</span>:entity];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add predicate to search by name</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSPredicate</span> *predicate = [<span style="color: #703daa;">NSPredicate</span> <span style="color: #3d1d81;">predicateWithFormat</span>:<span style="color: #d12f1b;">@"name == %@"</span>,name]; </div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setPredicate</span>:predicate];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSManagedObject</span> *aContact = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *objects = [<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">executeFetchRequest</span>:fetchRequest <span style="color: #3d1d81;">error</span>:&error];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([objects <span style="color: #3d1d81;">count</span>]==<span style="color: #272ad8;">0</span>) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"no matches found"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
aContact = [objects <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"name=%@, address=%@, phone=%@"</span>,[aContact <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"name"</span>], [aContact <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"address"</span>],[aContact <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"phone"</span>]); </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> aContact;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
18.4 delete particulate contact by Name</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSFetchRequest</span> *fetchRequest = [[<span style="color: #703daa;">NSFetchRequest</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSEntityDescription<span style="color: black;"> *entity = [</span>NSEntityDescription<span style="color: black;"> </span><span style="color: #3d1d81;">entityForName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span><span style="color: #3d1d81;">inManagedObjectContext</span><span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setEntity</span>:entity]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSPredicate</span> *predicate = [<span style="color: #703daa;">NSPredicate</span> <span style="color: #3d1d81;">predicateWithFormat</span>:<span style="color: #d12f1b;">@"name == %@"</span>, name];</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"my del predicate is :%@"<span style="color: black;">,predicate);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setPredicate</span>:predicate];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *fetchedObjects = [<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">executeFetchRequest</span>:fetchRequest <span style="color: #3d1d81;">error</span>:&error]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([fetchedObjects <span style="color: #3d1d81;">count</span>] ><span style="color: #272ad8;">0</span>) {</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//delete object</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSManagedObject</span> *aContactObject= [fetchedObjects <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">deleteObject</span>:aContactObject];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Save everything after deletion</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">save</span>:&error]) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"The update was successful!"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} <span style="color: #bb2ca2;">else</span> {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"The update wasn't successful: %@"<span style="color: black;">, [error </span><span style="color: #3d1d81;">localizedDescription</span><span style="color: black;">]);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"no matches found"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
These useful methods we can reuse anywhere in our app just by passing params</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #e32400;"><b>Note : </b></span>I add <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#pragma mark </span>the to make more clear and formatted coding style and easy to find any stuff in file.</div>
<div style="font-family: Helvetica; font-size: 12px;">
shortly I am going to write one article on <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#pragma mark,</span> how to use them in iOS? also what are advantages?</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>CoreDataHelper.m</b></span> file look like</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataHelper.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 01/04/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"CoreDataHelper.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> CoreDataHelper</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> context;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> objectModel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> coordinator;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - COREDATA -INITILIZE</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #4f8187;">CoreDataHelper</span> *coreDataHelper;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">CoreDataHelper</span> *) initCoreDataHelper{ </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">coreDataHelper</span> == <span style="color: #bb2ca2;">nil</span>) { </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>coreDataHelper<span style="color: black;"> = [[</span>CoreDataHelper<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">coreDataHelper</span> <span style="color: #31595d;">initializeContext</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>coreDataHelper<span style="color: black;">; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - COREDATA -MANAGE LIFE CYCLE</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//1. to get the dir path where we store our database file</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getApplicationDocumentsDirectoryPath{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSArray</span><span style="color: black;"> *paths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *basePath = ([paths <span style="color: #3d1d81;">count</span>] > <span style="color: #272ad8;">0</span>) ? [paths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>] : <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> basePath;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// 2. to manage object model</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSManagedObjectModel</span> *) initilizeManagedObjectModel{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">objectModel</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>objectModel<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSURL</span><span style="color: black;"> *modelURL = [[</span><span style="color: #703daa;">NSBundle</span><span style="color: black;"> </span>mainBundle<span style="color: black;">] </span>URLForResource<span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span>withExtension<span style="color: black;">:</span><span style="color: #d12f1b;">@"momd"</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">objectModel</span> = [[<span style="color: #703daa;">NSManagedObjectModel</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithContentsOfURL</span>:modelURL]; </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>objectModel<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// 3.to create core data </div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSPersistentStoreCoordinator</span> *) initilizeManagedPersistentStoreCoordinator{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">coordinator</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>coordinator<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSURL</span><span style="color: black;"> *storeUrl = [</span><span style="color: #703daa;">NSURL</span><span style="color: black;"> </span>fileURLWithPath<span style="color: black;">:[[</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span><span style="color: #31595d;">getApplicationDocumentsDirectoryPath</span><span style="color: black;">]</span>stringByAppendingPathComponent<span style="color: black;">: </span><span style="color: #d12f1b;">@"Contacts.sqlite"</span><span style="color: black;">]]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">coordinator</span><span style="color: black;"> = [[</span>NSPersistentStoreCoordinator<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">initWithManagedObjectModel</span>:[<span style="color: #bb2ca2;">self</span> <span style="color: #31595d;">initilizeManagedObjectModel</span>]];</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> (![</span><span style="color: #4f8187;">coordinator</span><span style="color: black;"> </span>addPersistentStoreWithType<span style="color: black;">:</span><span style="color: #703daa;">NSSQLiteStoreType</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">configuration</span>:<span style="color: #bb2ca2;">nil</span> <span style="color: #3d1d81;">URL</span>:storeUrl <span style="color: #3d1d81;">options</span>:<span style="color: #bb2ca2;">nil</span> <span style="color: #3d1d81;">error</span>:&error]) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Unresolved error %@, %@"</span>, error, [error <span style="color: #3d1d81;">userInfo</span>]);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">abort</span>();</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>coordinator<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//4. to manage object context </div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) initializeContext{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">context</span> == <span style="color: #bb2ca2;">nil</span>) { </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSPersistentStoreCoordinator</span><span style="color: black;"> *acoordinator = [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>initilizeManagedPersistentStoreCoordinator<span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">context</span><span style="color: black;"> = [[</span>NSManagedObjectContext<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">setPersistentStoreCoordinator</span>:acoordinator]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//5. to save context when app is going to be close/quit</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) saveCurrentContext{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">context</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">hasChanges</span>] && ![<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">save</span>:&error]) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Unresolved error %@, %@"</span>, error, [error <span style="color: #3d1d81;">userInfo</span>]);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">abort</span>();</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - COREDATA -INSERT</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName:(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO{ </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSManagedObject</span> *newContact; </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> newContact = [</span><span style="color: #703daa;">NSEntityDescription</span><span style="color: black;"> </span>insertNewObjectForEntityForName<span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span>inManagedObjectContext<span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[newContact <span style="color: #3d1d81;">setValue</span>:name <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[newContact <span style="color: #3d1d81;">setValue</span>:address <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[newContact <span style="color: #3d1d81;">setValue</span>:phoneNO <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"phone"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">save</span>:&error]) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Contact saved"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Error occured while saving"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - COREDATA -SELECT / VIEW ALL DATA</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSFetchRequest</span> *fetchRequest = [[<span style="color: #703daa;">NSFetchRequest</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSEntityDescription<span style="color: black;"> *entity = [</span>NSEntityDescription<span style="color: black;"> </span><span style="color: #3d1d81;">entityForName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span><span style="color: #3d1d81;">inManagedObjectContext</span><span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setEntity</span>:entity];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *objects = [<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">executeFetchRequest</span>:fetchRequest <span style="color: #3d1d81;">error</span>:&error]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([objects <span style="color: #3d1d81;">count</span>]><span style="color: #272ad8;">0</span>) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span> (<span style="color: #703daa;">NSManagedObject</span> *aContact <span style="color: #bb2ca2;">in</span> objects) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"name=%@, address=%@, phone=%@"<span style="color: black;">,[aContact </span><span style="color: #3d1d81;">valueForKey</span><span style="color: black;">:</span>@"name"<span style="color: black;">],[aContact </span><span style="color: #3d1d81;">valueForKey</span><span style="color: black;">:</span>@"address"<span style="color: black;">],[aContact </span><span style="color: #3d1d81;">valueForKey</span><span style="color: black;">:</span>@"phone"<span style="color: black;">]);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"no matches found"</span>); </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - COREDATA - SEARCH</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//this method will returns an Object which contains one person's Contact info details</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSManagedObject</span> *) searchContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSFetchRequest</span> *fetchRequest = [[<span style="color: #703daa;">NSFetchRequest</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSEntityDescription<span style="color: black;"> *entity = [</span>NSEntityDescription<span style="color: black;"> </span><span style="color: #3d1d81;">entityForName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span><span style="color: #3d1d81;">inManagedObjectContext</span><span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setEntity</span>:entity];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add predicate to search by name</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSPredicate</span> *predicate = [<span style="color: #703daa;">NSPredicate</span> <span style="color: #3d1d81;">predicateWithFormat</span>:<span style="color: #d12f1b;">@"name == %@"</span>,name]; </div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setPredicate</span>:predicate];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSManagedObject</span> *aContact = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *objects = [<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">executeFetchRequest</span>:fetchRequest <span style="color: #3d1d81;">error</span>:&error];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([objects <span style="color: #3d1d81;">count</span>]==<span style="color: #272ad8;">0</span>) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"no matches found"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
aContact = [objects <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"name=%@, address=%@, phone=%@"</span>,[aContact <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"name"</span>], [aContact <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"address"</span>],[aContact <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"phone"</span>]); </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> aContact;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - COREDATA - DELETE</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSFetchRequest</span> *fetchRequest = [[<span style="color: #703daa;">NSFetchRequest</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSEntityDescription<span style="color: black;"> *entity = [</span>NSEntityDescription<span style="color: black;"> </span><span style="color: #3d1d81;">entityForName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"Contacts"</span><span style="color: black;"> </span><span style="color: #3d1d81;">inManagedObjectContext</span><span style="color: black;">:</span><span style="color: #4f8187;">context</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setEntity</span>:entity]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSPredicate</span> *predicate = [<span style="color: #703daa;">NSPredicate</span> <span style="color: #3d1d81;">predicateWithFormat</span>:<span style="color: #d12f1b;">@"name == %@"</span>, name];</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"my del predicate is :%@"<span style="color: black;">,predicate);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[fetchRequest <span style="color: #3d1d81;">setPredicate</span>:predicate];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSError</span> *error = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *fetchedObjects = [<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">executeFetchRequest</span>:fetchRequest <span style="color: #3d1d81;">error</span>:&error]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([fetchedObjects <span style="color: #3d1d81;">count</span>] ><span style="color: #272ad8;">0</span>) {</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//delete object</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSManagedObject</span> *aContactObject= [fetchedObjects <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">deleteObject</span>:aContactObject];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Save everything after deletion</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">context</span> <span style="color: #3d1d81;">save</span>:&error]) {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"The update was successful!"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} <span style="color: #bb2ca2;">else</span> {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"The update wasn't successful: %@"<span style="color: black;">, [error </span><span style="color: #3d1d81;">localizedDescription</span><span style="color: black;">]);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"no matches found"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Bravo!! Bravo!!.. keep moving like a RockStar \m/</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - VI (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add some UITextFields, UIButtons,UILabel and Title Bar on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open <b>ViewController.xib</b> file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Let's drag UINavigationBar from Object library double click on it and give title as "Core Data : Contact Info", (we will use this for just showing app Title)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. TextFields : </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2.1 now drag TextFields for Taking input <b>Name</b> ,adjust full width, then go to <b>Attribute <span class="Apple-tab-span" style="white-space: pre;"> </span>Inspector </b>and update Placeholder value as "enter name here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2.2 do same for next TextField for Taking input <b>Address</b> and change its Placeholder value as <span class="Apple-tab-span" style="white-space: pre;"> </span>"enter <span class="Apple-tab-span" style="white-space: pre;"> </span>address here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2.3. drag one more TextField for Taking input <b>Phone No</b> and change its Placeholder value as <span class="Apple-tab-span" style="white-space: pre;"> </span>"enter 10 digit phone no" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. UILabel : drag one label and double click on it, change text as "Note : for search and delete only enter name"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. UIButtons: drag 4 Buttons and double click and give them name as <b>Save</b>, <b>View All</b>, <b>Search</b>, and <b>Delete</b> respectively .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now adjust all these items on your Layout as per shown in below screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzbpP3v5A0D8leKC7aAgDlecq9Q1Tw4mPozx_EQsVGUkobZrlb2_W94qgdTJnoTqaRnkmdpeVI3LsfbhZTH_x6jHzie-KbDI8JavCaxJ_y2Mxft18WYaBS6rIV8DfSUlMMWruK7uirMz63/s1600/Screen+16.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzbpP3v5A0D8leKC7aAgDlecq9Q1Tw4mPozx_EQsVGUkobZrlb2_W94qgdTJnoTqaRnkmdpeVI3LsfbhZTH_x6jHzie-KbDI8JavCaxJ_y2Mxft18WYaBS6rIV8DfSUlMMWruK7uirMz63/s320/Screen+16.png" width="220" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - VII (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UITextFields and IBAction methods for UIButtons .</div>
<div style="font-family: Helvetica; font-size: 12px;">
So just open ViewController.xib </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Create IBOutlets</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Select UITextField (which says - 'enter name here') --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqJQ0TbFJN8bdh7biaZYQsDsy5Ye3j10IjDJc8qe87A8kUVHsryLkk6LwlTzkP4messF1q4yVIkJd_ADUAGnsG7nhsTDSYD-OsVoGZb0dFEb1i0GDYXSsIVK6b0o7q9HC0nNskbf6YHcas/s1600/Screen+18.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="181" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqJQ0TbFJN8bdh7biaZYQsDsy5Ye3j10IjDJc8qe87A8kUVHsryLkk6LwlTzkP4messF1q4yVIkJd_ADUAGnsG7nhsTDSYD-OsVoGZb0dFEb1i0GDYXSsIVK6b0o7q9HC0nNskbf6YHcas/s320/Screen+18.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.3 Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">nameTextField</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ0bc7BEixmHEWGC0WU929rnfilsuecetvJNUzEvRbVyEpJ_jtxCjxLvIrMzce66eHfonZXRBjaIBvjUa27oi5IBS0IXIEh5d-Ig71tANfTe2ds1AK2lSkorH7GMEQ81Bbp65wwVgf5sTY/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="99" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ0bc7BEixmHEWGC0WU929rnfilsuecetvJNUzEvRbVyEpJ_jtxCjxLvIrMzce66eHfonZXRBjaIBvjUa27oi5IBS0IXIEh5d-Ig71tANfTe2ds1AK2lSkorH7GMEQ81Bbp65wwVgf5sTY/s320/Screen+13.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see below line added in our ViewController's header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *nameTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.4 do the same for next two TextFields and give them name as<span style="font-family: Menlo; font-size: 11px;"> "addressTextField" </span>and<span style="font-family: Menlo; font-size: 11px;"> "phoneNoTextField" </span>respectively<span style="font-family: Menlo; font-size: 11px;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time you can see two IBOutlets created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *addressTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *phoneNoTextField;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Create IBAction methods</div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 Select UIButton (which says -'Save') --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 Click on <span style="color: #4f7a28;"><b>Touchup Inside</b></span> in "Sent Events" option and drag cursor just below to new created IBOutlets, and put the method name "" in pop window</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-AfF_t3hf8hgLHeofXUBt-8uLZ9pgGu-OsjhdffgAs1b4EobRZgOrdFtW9in6ZdB_ckci4CIrl9SbMD_jPWktqg9yeGpas5gzrkxf5ZSiZyXmPQDDKV6ApbsGZjxuiDuZqLzT3CFv7maR/s1600/Screen+14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-AfF_t3hf8hgLHeofXUBt-8uLZ9pgGu-OsjhdffgAs1b4EobRZgOrdFtW9in6ZdB_ckci4CIrl9SbMD_jPWktqg9yeGpas5gzrkxf5ZSiZyXmPQDDKV6ApbsGZjxuiDuZqLzT3CFv7maR/s1600/Screen+14.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see new method is added in our ViewController's header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.3 do the same for next three Buttons and give methods name as<span style="font-family: Menlo; font-size: 11px;"> "viewAllContactsInfo","searchContactInfo" </span>and<span style="font-family: Menlo; font-size: 11px;"> "deleteContactInfo" </span>respectively<span style="font-family: Menlo; font-size: 11px;">.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time you can see three new IBAction methods created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - VIII (Hook Up Delegate with File Owner to Handle Keypad Go )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here we need to hook up our TextFields Delegate to File Owner, so we can use its method to hand Keypad.</div>
<div style="font-family: Helvetica; font-size: 12px;">
when use Tap Return key while typing then keypad should go back.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Open ViewController.xib</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select UITextField (which says - 'enter name here') --> go the Connection Inspector --> drag cursor from Delegate to File owner (Right to Left)</div>
<div style="font-family: Helvetica; font-size: 12px;">
as shown in below screen shot</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjqLcZjTg2wEnURTnsFgZeJCTGHs22Z5c8J26yL0V1yqcQdRpu8kaGmUO-Y6LP0NjdAPYlih7C6yMNTrdWWkq3fbvSHp3voEUQd0ksze4erj-mz4AoQxQ2L6Z7YhQbKb__TjcJzFWHlWw/s1600/Screen+22.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="175" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjqLcZjTg2wEnURTnsFgZeJCTGHs22Z5c8J26yL0V1yqcQdRpu8kaGmUO-Y6LP0NjdAPYlih7C6yMNTrdWWkq3fbvSHp3voEUQd0ksze4erj-mz4AoQxQ2L6Z7YhQbKb__TjcJzFWHlWw/s320/Screen+22.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. repeat same for next two Text Fields (Address, Phone No)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #e32400;"><i>Note</i></span><i> : you can achieve same by doing it programmatically in ViewController's </i><b><i>viewDidLoad</i></b><i> method.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
nameTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
addressTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;">=</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;">=</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are about to Accomplish our goal, So, stay tune with RDC.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
This time we use all the hard-work we have done in Model or Helper classes.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">Open </span>ViewController.h<span style="color: black; font-family: Helvetica; font-size: 12px;"> file</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. we need to use Model class instance hence add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class </span>for that</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>Contacts<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. add protocol <span style="color: #703daa;">UITextFieldDelegate </span>because we will enable Keypad Go back when user hit Return Key on any TextFiled</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UITextFieldDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. You can see some IBOutlets and IBActions methods we already Added By Xcode, we did it From UI.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. declare property for our Model class instance</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #4f8187;">Contacts</span><span style="color: black;"> *aContact;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
4. declare property of TextField class instance, we will use this, for which TextFiled is active for sending keypad back.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *active_text;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Good! save this File.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 29/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>Contacts<span style="color: black;">; </span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"> <</span>UITextFieldDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *nameTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *addressTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *phoneNoTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #4f8187;">Contacts</span><span style="color: black;"> *aContact;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *active_text;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#import </span>statement for Model class and CoreDataHelper, we are going to use them in this </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"CoreDataHelper.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"Contacts.h"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> addressTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> phoneNoTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> active_text;</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> aContact;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>saveContactInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">phoneNoTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> && [address <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span> && [phone <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span>) { </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>insertContactInfoName<span style="color: black;">:name </span>Address<span style="color: black;">:address </span>PhoneNo<span style="color: black;">:phone]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>viewAllContactsInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//the result contacts we have printed on log in Helper class itself</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>selectAllContacts<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>searchContactInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSManagedObject</span><span style="color: black;"> *aContactObject =[[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>searchContactInfoByName<span style="color: black;">:name];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [aContactObject <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [aContactObject <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [aContactObject <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"phone"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@"Search Result"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"We found Name : %@, Address : %@, Phone No : %@"</span>,name,address,phone]</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">5. </span>update the body of <span style="font-family: Menlo; font-size: 11px;"><b>deleteContactInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span> <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> ) { </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>deleteContactInfoByName<span style="color: black;">:</span><span style="color: #4f8187;">nameTextField</span><span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span> <span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
6. now we will implement UITextFiled's Delegate method to handle Keypad Go Back when user Hit Return key</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>)textFieldDidBeginEditing:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">active_text</span> = textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>TRUE<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 29/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"CoreDataHelper.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"Contacts.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> addressTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> phoneNoTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> active_text;</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> aContact;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController Life Cycle Methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button click methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">phoneNoTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> && [address <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span> && [phone <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span>) { </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>insertContactInfoName<span style="color: black;">:name </span>Address<span style="color: black;">:address </span>PhoneNo<span style="color: black;">:phone]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//the result contacts we have printed on log in Helper class itself</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>selectAllContacts<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSManagedObject</span><span style="color: black;"> *aContactObject =[[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>searchContactInfoByName<span style="color: black;">:name];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [aContactObject <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [aContactObject <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [aContactObject <span style="color: #3d1d81;">valueForKey</span>:<span style="color: #d12f1b;">@"phone"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@"Search Result"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"We found Name : %@, Address : %@, Phone No : %@"</span>,name,address,phone]</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span> <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> ) { </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>deleteContactInfoByName<span style="color: black;">:</span><span style="color: #4f8187;">nameTextField</span><span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span> <span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UITextField Delegate methods for Keypad Return key</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>)textFieldDidBeginEditing:(<span style="color: #703daa;">UITextField</span> *)textField{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">active_text</span> = textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>TRUE<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 29/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now open AppDelegate.m file, we need to call one Helper class saveCurrentContext method to save the CoreData context when app is going to close by user.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. So import CoreDataHelper class here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"CoreDataHelper.h"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. update <b>applicationWillTerminate</b><span style="font-family: Menlo; font-size: 11px;"> </span>method this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillTerminate:(<span style="color: #703daa;">UIApplication</span> *)application{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>saveCurrentContext<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreDataDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 29/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"CoreDataHelper.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillTerminate:(<span style="color: #703daa;">UIApplication</span> *)application{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">CoreDataHelper</span><span style="color: black;"> </span>initCoreDataHelper<span style="color: black;">] </span>saveCurrentContext<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI7GxECvG3sl4jSFdzyUE0CtHZXL5843RgIvcS7j2dThbwphBVhUlskK6hmpnA9UnhmuyBFirjnnCC93lmKduIb6031A509A-eP6aktylj3zFWZx2eGuCe8-vW6bBp9cx2-kfjpqLa5Shh/s1600/Screen+23.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI7GxECvG3sl4jSFdzyUE0CtHZXL5843RgIvcS7j2dThbwphBVhUlskK6hmpnA9UnhmuyBFirjnnCC93lmKduIb6031A509A-eP6aktylj3zFWZx2eGuCe8-vW6bBp9cx2-kfjpqLa5Shh/s320/Screen+23.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can Find the ViewAll results in Console also.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkki6aDinZXeKpnCZWbjT9q0fy2Vs2t_ZUUPSKocmkr8EDoj59iYcdX7l7qOgfZ9rFdT1tiHrJTTQT_oF9bd2M0QSlXYdBh006cP-L7TRFq7r7gj1YfT6ndiuYE1ybq8oSTwHnzGYZ4OMa/s1600/Screen+24.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkki6aDinZXeKpnCZWbjT9q0fy2Vs2t_ZUUPSKocmkr8EDoj59iYcdX7l7qOgfZ9rFdT1tiHrJTTQT_oF9bd2M0QSlXYdBh006cP-L7TRFq7r7gj1YfT6ndiuYE1ybq8oSTwHnzGYZ4OMa/s320/Screen+24.png" width="219" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <span style="font-size: 14px;"><a href="https://www.opendrive.com/files?M182OTI0MzQ5X1FBR1ZQ" target="_blank"><span style="color: #38761d;"><b>CoreDataDemo.zip (87.41 KB)</b></span></a></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
<div>
<br /></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com9Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-26695053282469636812013-03-28T06:31:00.000-07:002013-03-28T06:33:28.639-07:00Handling Soft Keypad in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Handling the Soft Keyboard in iPhone application is bit painful stuff specially when we are beginner.</div>
<div style="font-family: Helvetica; font-size: 12px;">
when I used text field first time after editing text I clicked on return key, Hit Enter bla bla..and I was shocked What the hell.. keypad is locked and didn't go away, and even I was not able to see my other text fields and Login button those were hidden by keypad.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Then I started digging on it, how to handle keypad in this situation and got some tricky solutions and started using in my projects.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Today I'll write Simple Tutorial to handle keypad in iOS applications</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Please! stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b><i></i></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
There are three simple ways to handle keypad here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Keypad go back when Button clicked.</div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Keypad go back when user click on <b>Return</b> or <b>Done</b> button on keypad.</div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Keypad go back when user Touch on Background screen/view. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEO6dN76jJnDqIndBpYSvKuIcQh8kU2us29A9blgJ3OxiDekZ_0nSHNY9UgxK0K_s_oq9Dol8d6ZXx7CrqxU3jMPiqet1Ub_uO6A4ikPZK0iBJTLL6q-nfRvGSjIAgainVaZKv872djsHG/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEO6dN76jJnDqIndBpYSvKuIcQh8kU2us29A9blgJ3OxiDekZ_0nSHNY9UgxK0K_s_oq9Dol8d6ZXx7CrqxU3jMPiqet1Ub_uO6A4ikPZK0iBJTLL6q-nfRvGSjIAgainVaZKv872djsHG/s1600/Screen+0.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px; margin-bottom: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6.1 , Xcode 4.6, and MAC OS X Lion 10.8.3</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you <b>Single View Application</b> templet as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiae7mtyg1SdW-9FvyxWXOLIVWb6f6AMCLbp8p5qeleIw66F4mnwIRlvE6Y2kT4WqadAIsBwMYs6qXra6bWC4N8NTCrJTL5e2aQVrKitmMlI5uqoDTdwUjjRfzmefcepOgHQee-bz0AV3M6/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="97" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiae7mtyg1SdW-9FvyxWXOLIVWb6f6AMCLbp8p5qeleIw66F4mnwIRlvE6Y2kT4WqadAIsBwMYs6qXra6bWC4N8NTCrJTL5e2aQVrKitmMlI5uqoDTdwUjjRfzmefcepOgHQee-bz0AV3M6/s320/Screen+3.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
---------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>KeypadDemo<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0F50T7wFP9cWdfiH7nnCLd_Cv7jugw0Fz-e3VY1qdhKKJ-mskon9MOD0GJbUTQgMx2RZp03VI_aRVvXxUY3w9LV1ZK4cUJf_3UjQ-SxU-I136n_NAVRrkKs6Dlj2uVBoSBbeAoppbZW6y/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0F50T7wFP9cWdfiH7nnCLd_Cv7jugw0Fz-e3VY1qdhKKJ-mskon9MOD0GJbUTQgMx2RZp03VI_aRVvXxUY3w9LV1ZK4cUJf_3UjQ-SxU-I136n_NAVRrkKs6Dlj2uVBoSBbeAoppbZW6y/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Open <b>ViewController.xib</b> file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. drag an UINavigationBar and double click on it --> put name "Handle Keypad" (It is just Title of app)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. now drag two UITextFields for User Name and Password input.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. select TextField --> go to Attributes Inspector --> put Placeholder as "enter username here"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWqquVhJanauc4AMBrXC1KPWxWSeKuDA1JjmVZFEUeahjjGTCTBzlPUS5KdXYtP_6UU7eegpvw-mCw2K6AnbUDPb3KoJjy7lXdnGkJqn4KYUaXsD8PhZIT4coKKlXhN42IwyYvhytCUXjp/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWqquVhJanauc4AMBrXC1KPWxWSeKuDA1JjmVZFEUeahjjGTCTBzlPUS5KdXYtP_6UU7eegpvw-mCw2K6AnbUDPb3KoJjy7lXdnGkJqn4KYUaXsD8PhZIT4coKKlXhN42IwyYvhytCUXjp/s1600/Screen+3.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. do the same for other text field --> put Placeholder as "enter password here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
5. drag UIButton from object library and double click on it, update name as "Login" --> save this file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
6. change background colour to <span style="color: #5e30eb;">Blue </span>(optional)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCETdW__jPuCa7KMz4-66L1FJKOlXnnyOVH4Dn-l175ThqI0h-gQt2QpzPQO3z_q8MBfKI-qQySFLh10mL8_gU01365jHwlgGV4GQeVd7jYe3q6gJGUNo_KRtRFYDzGPyFAvl3O6mL2Qeu/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCETdW__jPuCa7KMz4-66L1FJKOlXnnyOVH4Dn-l175ThqI0h-gQt2QpzPQO3z_q8MBfKI-qQySFLh10mL8_gU01365jHwlgGV4GQeVd7jYe3q6gJGUNo_KRtRFYDzGPyFAvl3O6mL2Qeu/s320/Screen+4.png" width="220" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to create two IBOutlets for TextFields and an IBAction method for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
open <b>ViewController.xib</b> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Create IBOutlets</b></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
1. Select Text Field for UserName-- > press Ctrl +Click and drag cursor between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span> (in Right side Header File). </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
2. in the pop up window, put name as "<span style="color: black;">userNameTextField</span>" and connect.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
you will find one IBOutlet property is created in header file</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *userNameTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
3.do the same for password Text Field, it will create below line of code in your header file.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *passwordTextField;</span></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Create IBActions</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. select 'Keypad Go Back' Button -- > press Ctrl +Click and drag cursor between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span> (in Right side Header File). </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. in the pop up window <span style="color: #e32400;">make sure you change </span>Connection = <b>Action </b>and give method name as "keypadGoBack" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you will find one IBAction method is created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #703daa;">UIButton</span> *)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYrHOjhemwDTrCSnHHuQRuRsO4LKTAs5hhRqFfpEVh4q6C_2v5dIaxtieubqbhoqRgPY_l5NX4Q4eDUPua1Kof-KtbqZzCYK3f4obPXZWOPPEaxODErdBsRX606EQW4DGApcHIw-zdKo5f/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYrHOjhemwDTrCSnHHuQRuRsO4LKTAs5hhRqFfpEVh4q6C_2v5dIaxtieubqbhoqRgPY_l5NX4Q4eDUPua1Kof-KtbqZzCYK3f4obPXZWOPPEaxODErdBsRX606EQW4DGApcHIw-zdKo5f/s1600/Screen+6.png" /></a></div>
<div style="font-family: Menlo; font-size: 11px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. do the same for Login button and give method name as "<i>loginButtonClicked</i>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you will find one IBAction method is created in header file and empty body is added in implementation file (.m file ) too</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)loginButtonClicked:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #0061ff; font-family: Helvetica; font-size: 12px;">
At this time If you will run the application you will get stuck on keypad because so far we haven't any logic to handle this.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzu1og0qCp-M-XJVrUQASFeNUrl7Bt1rLvgNKOvZdJ7Ukh6hJdPu3Dk5uqVcmdn6Xqn3ORLh5ef6roVNN5C1diBwL93U_0107W8oOFbsu4FKRO_P53w4p8ERAxVvSDABVNJUwoVU7y0dIu/s1600/screen+121.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzu1og0qCp-M-XJVrUQASFeNUrl7Bt1rLvgNKOvZdJ7Ukh6hJdPu3Dk5uqVcmdn6Xqn3ORLh5ef6roVNN5C1diBwL93U_0107W8oOFbsu4FKRO_P53w4p8ERAxVvSDABVNJUwoVU7y0dIu/s320/screen+121.png" width="213" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So here we go..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
First is First!! Make sure your app delegate files code should be like given below</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
---------------------------------------------------------------------------------------------------------------------------------------<span style="color: #008400; font-family: Menlo; font-size: 11px;">//</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
There are three simple ways we will learn to handle keypad here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Keypad go back when Button clicked.</div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Keypad go back when user click on <b>Return</b> or <b>Done</b> button on keypad.</div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Keypad go back when user Touch on Background screen/view. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #669c35; font-family: Helvetica; font-size: 18px;">
1. Keypad go back when Button clicked</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Generally we use this solution when we click on any button and keypad go away.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
First make sure our <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.h</span> file code should be like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *userNameTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *passwordTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)loginButtonClicked:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay let's do some code ..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
open implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.m</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> userNameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> passwordTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. add below code in <b><i>keypadGoBack</i></b> method body this way</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">userNameTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">passwordTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it, Save file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So This time our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> userNameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> passwordTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">userNameTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">passwordTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)loginButtonClicked:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
On this stage if you will run the application, you will see, when you click on KeypadGoBack the soft keypad goes away.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #669c35; font-family: Helvetica; font-size: 18px;">
2. Keypad go back when user click on Return or Done button on keypad</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Generally we use this solution when we click on <b>Return</b> or <b>Done</b> button and keypad go away.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
This time we will implement UITextField delegate methods to handle Return key on soft keypad.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">1. add </span><span style="color: #703daa;">UITextFieldDelegate</span><span style="font-family: Helvetica; font-size: 12px;"> in </span><span style="color: #008400;">ViewController.h</span><span style="font-family: Helvetica; font-size: 12px;"> file's </span><span style="color: #bb2ca2;">@interface</span><span style="font-family: Helvetica; font-size: 12px;"> this way</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UITextFieldDelegate<span style="color: black;">></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So This time our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UITextFieldDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *userNameTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *passwordTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)loginButtonClicked:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now open implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.m</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add below code in viewDidLoad method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
userNameTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
passwordTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
//or same you can achieve by hookup TextField Delegate in InterfaceBuilder also</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. now add <span style="font-family: Menlo; font-size: 11px;"> <b><i>UITextFieldDelegate</i></b> </span>method just before <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@end</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it, Save file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So This time our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> userNameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> passwordTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>userNameTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>passwordTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">userNameTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">passwordTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)loginButtonClicked:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma -mark UITextField delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
On this stage if you will run the application, you will see, when you click on Keypad's <b>Return/Done</b> key soft keypad goes away.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #669c35; font-family: Helvetica; font-size: 18px;">
3. Keypad go back when user Touch on Background screen/view. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
This one is my favourite solution, Where ever I am just need to touch on background view and keypad go like a flying Zebra.. :p</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Easy and suitable in all situation</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let's make it real..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. open <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.m </span>file and and this method at the end of the file and before <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@end</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">IBAction</span>) touchOnBackground{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">userNameTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">passwordTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So This time our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// KeypadDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 28/03/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> userNameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> passwordTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - view controller's life cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>userNameTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>passwordTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button click methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">userNameTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">passwordTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)loginButtonClicked:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma -mark UITextField delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma - mark method for touch on background </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">IBAction</span>) touchOnBackground{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">userNameTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">passwordTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. now open ViewController.xib file --> select/click on background view (blue colour)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
select Identity Inspector (In top right side) --> <span style="color: #e32400;">change Class = UIControl </span>(default it's UIView)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU7u9iFvHBUm5KHIG4EgWQFAqJWZeN4ULCLIRjYuV-515tFv5HUICD8fIoWW_CMKCOl7f6a-ipjJ75YXvNBE_Ix8vfevgpVnqwPzo2Ur1HDnumDN56jY5GHI2iJlEEEEm3UpavED5qoZY_/s1600/Screen8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU7u9iFvHBUm5KHIG4EgWQFAqJWZeN4ULCLIRjYuV-515tFv5HUICD8fIoWW_CMKCOl7f6a-ipjJ75YXvNBE_Ix8vfevgpVnqwPzo2Ur1HDnumDN56jY5GHI2iJlEEEEm3UpavED5qoZY_/s1600/Screen8.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. now make sure your background still selected -->select Connections Inspector, you can see list of delegate method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqLou9tNVw-Dl5b3IICM9JOyPF-H_O1yYJrLhlCV03k1x2toonXtXcXdf_iZCRFfOfan1nvuVH7TQYV5tea5RXoXHonLRQBD5D22EX5ctorivAt4_erms5givv2tBq_eCQvowiynf7PRjQ/s1600/screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="194" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqLou9tNVw-Dl5b3IICM9JOyPF-H_O1yYJrLhlCV03k1x2toonXtXcXdf_iZCRFfOfan1nvuVH7TQYV5tea5RXoXHonLRQBD5D22EX5ctorivAt4_erms5givv2tBq_eCQvowiynf7PRjQ/s320/screen+9.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
so click on Touch Down method and drag cursor to Left side File Owner (Yellow Cube) --> select <span style="font-family: Menlo; font-size: 11px;">touchOnBackground </span>as shown in below picture.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDqLwdbAnB6Dr7Vzvr-6GANJODB3YbYVmCgKE38A-_OnYjuB7UzUjOEhOHDMuFRiotHVHpW25QisKCAy6eBvBjnH1lJHJTXPcRvha9Ix_ajrmzYAeNB_wvaWxJSbM2a0_H_NV_EUOtoWot/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDqLwdbAnB6Dr7Vzvr-6GANJODB3YbYVmCgKE38A-_OnYjuB7UzUjOEhOHDMuFRiotHVHpW25QisKCAy6eBvBjnH1lJHJTXPcRvha9Ix_ajrmzYAeNB_wvaWxJSbM2a0_H_NV_EUOtoWot/s1600/Screen+10.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it save file and run application for the results.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
This time if we click on anywhere on background , keypad will go away.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! we did it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
here is the result screen</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9HvPa0S91GFIsYhtVoXUkxUJRqNEZsV0glBYgZWDUIBN8BUCnnsernbR1FprXiPVGsHWM1Ay6paBHuvbw8xEpSyM5ptRaNH7nimFIJTTa4NhpxeoVKy6rQdKSJTMfVLKRArLRJKCxZBPu/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9HvPa0S91GFIsYhtVoXUkxUJRqNEZsV0glBYgZWDUIBN8BUCnnsernbR1FprXiPVGsHWM1Ay6paBHuvbw8xEpSyM5ptRaNH7nimFIJTTa4NhpxeoVKy6rQdKSJTMfVLKRArLRJKCxZBPu/s400/Screen+0.png" width="205" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <b style="font-size: 14px;"><a href="https://www.opendrive.com/files?M182ODc1NDIzX1lsSDly" target="_blank"><span style="color: #6aa84f;">KeypadDemo.zip (66.71 KB)</span></a></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !!</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-58373643441752400692013-03-12T02:32:00.000-07:002013-03-12T02:42:03.512-07:00How to store info in application preferences iPhone (NSUserDefaults Tutorial)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Sometime we need to store, our application information on Application preference for short time.</div>
<div style="font-family: Helvetica; font-size: 12px;">
iOS provide NSUserDefaults to achieve this. we can store any string,array etc into app preferences in the form of Key-Value using NSUserDefaults class.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwWfRaEpP5Gb5qeRitqxTBpHFt6xS1eu-IpnAEFB1yZlTrgZvjayHSrxPZmvIvgfuDlxGSoTX2eJhd-rOvIoqFPxwOy_08OnTDs5Xs03lakH8QYLbEPnIvnvV3ASJUS84pR3ewVmFPVSYv/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwWfRaEpP5Gb5qeRitqxTBpHFt6xS1eu-IpnAEFB1yZlTrgZvjayHSrxPZmvIvgfuDlxGSoTX2eJhd-rOvIoqFPxwOy_08OnTDs5Xs03lakH8QYLbEPnIvnvV3ASJUS84pR3ewVmFPVSYv/s400/Screen+0.png" width="205" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b><i></i></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Before starting You may like to know our preferences details</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span style="color: #008400;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Preferences Key : </span>Message_Text |</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;">|</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Key Value Type : <span style="color: black;">NSString<span class="Apple-tab-span" style="white-space: pre;"> </span> |</span></div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you <b>Single View Application</b> templet as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
---------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>NSUserDefaultsDemo <span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld <span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option to enable ARC.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2k-brBhXMVi_jsnWHcwiomedZ2Hpmvo1-mYT-9ySGEDIweqH9HsIb-PVuIYDDEv8fVQy24BOqevC-cNxp0xZxCWs4L9BenkF5z635AbYTgbyXeeGT4kTck25JoQxrD8Afv7gIOTUHFCCD/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2k-brBhXMVi_jsnWHcwiomedZ2Hpmvo1-mYT-9ySGEDIweqH9HsIb-PVuIYDDEv8fVQy24BOqevC-cNxp0xZxCWs4L9BenkF5z635AbYTgbyXeeGT4kTck25JoQxrD8Afv7gIOTUHFCCD/s320/Screen+2.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Add more ViewControllers)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
we need to Add one more UIViewController for second screen. create and give name as "NextViewController" this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. File --> New --> File --> Select Objective -C class templet (in Cocoa Touch option).</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. In the next window give file details</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class : <b>NextViewController</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Subclass of : <b>UIViewController</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "<i>With XIB for user interface</i>" option --> Next -->create. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So for now our application project structure look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTf86PUzTIadVIrfbGZyianez4mQf2fTFEKEV6D7mph5iZSAeheklUHogBGHJ_EbnuKXPQeBkf4XeATghxCnBpNBhyphenhyphen9b-3Z2kp_IQMXqaiONUKvDO8gyo8Idt3E19lAilBe6xdect-jdDI/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTf86PUzTIadVIrfbGZyianez4mQf2fTFEKEV6D7mph5iZSAeheklUHogBGHJ_EbnuKXPQeBkf4XeATghxCnBpNBhyphenhyphen9b-3Z2kp_IQMXqaiONUKvDO8gyo8Idt3E19lAilBe6xdect-jdDI/s320/Screen+3.png" width="184" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Open <b>ViewController.xib</b> file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. drag UIButton from object library and double click on it, update name as "Next" --> save this file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. change background color to <span style="color: #669c35;">Green</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now open <b>NextViewController.xib</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. drag one UILabel and double click on it, change value to "We go the message is :"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">5. again </span>drag one more UILabel on center of Layout double click and change name "result message".</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
6. change background color to <span style="color: #5e30eb;">Blue</span></div>
<div style="color: #5e30eb; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoN01C9gR4gOAt_9UGrhHtzQVCklwEfl6OWDJx-o_4QeeGPgTq0C0qbNHNE7yO_N4giS_ZHDBKVNt4ick1z7NWOGvwCwntsY3ddJ1FbIMubwbqM45RNdwccZMi1ICk5TTmEIDCXkVFA6c1/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoN01C9gR4gOAt_9UGrhHtzQVCklwEfl6OWDJx-o_4QeeGPgTq0C0qbNHNE7yO_N4giS_ZHDBKVNt4ick1z7NWOGvwCwntsY3ddJ1FbIMubwbqM45RNdwccZMi1ICk5TTmEIDCXkVFA6c1/s320/Screen+4.png" width="218" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBAction methods for UIButton .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So just open <b>ViewController.xib</b> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Create IBAction</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. select <b>Next</b> Button -- > press Ctrl +Click and drag cursor between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span> (in Right side Header File). </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. in the pop up window make sure you change Connection type Outlet to --> <b>Action, </b>and give method name as "<i>goToNextView</i>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglhyphenhyphenyenD_v4JKXdcKF3WlAeOm-HEsbvu4pcQV26Xh7zCoky73ksVFWb8AHHDGnBEZPHUAP5TYSunev24qPTghCE0Ncs3o2wYt3ObF1oyRgRACEytcWltquKamw-noWRwUrYUt3YCRhtunE/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglhyphenhyphenyenD_v4JKXdcKF3WlAeOm-HEsbvu4pcQV26Xh7zCoky73ksVFWb8AHHDGnBEZPHUAP5TYSunev24qPTghCE0Ncs3o2wYt3ObF1oyRgRACEytcWltquKamw-noWRwUrYUt3YCRhtunE/s1600/Screen+5.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you will find one IBAction method is created in header file and empty body is added in implementation file (.m file ) too</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextView:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Create IBOutlet</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
open <b>NextViewController.xib</b> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. select Label (name is "<i>result message</i>")-- > press Ctrl +Click and drag cursor between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span> (in Right side Header File). </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. in the pop up window, put name as "<span style="color: #4f8187; font-family: Menlo; font-size: 11px;">receivedMessageLabel</span>" and connect.</div>
<div style="font-family: Helvetica; font-size: 12px;">
you will find one IBOutlet property is created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">weak</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #bb2ca2;">IBOutlet</span> <span style="color: #703daa;">UILabel</span> *receivedMessageLabel;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - V (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
To enable Navigation Controller in our application we need to add it in app delegate.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So open AppDelegate.h</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. create UINavigationController with property </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> *rootController;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NSDefaultUserDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> *rootController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to AppDelegate.m file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. in <span style="font-family: Menlo; font-size: 11px;">didFinishLaunchingWithOptions </span>method initialize Navigation Controller, by adding ViewController as a Root.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">rootController</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithRootViewController<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">viewController</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. add navigation controller to UIWindow</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>rootController<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NSDefaultUserDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">]; </span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">rootController</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithRootViewController<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">viewController</span><span style="color: black;">]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>rootController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Open ViewController.h file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class</span> statement just below to <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#import </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>NextViewController<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. create strong property for NextViewController, We are going to load via Next Button</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">NextViewController</span> *nextViewController;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>NextViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">NextViewController</span> *nextViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextView:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now open ContactObject's implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.m</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nextViewController;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> messageTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. in <b>viewDidLoad</b> method put title for Current view</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"NSUserDefaults Demo"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. Now <span style="color: #e32400;"><b>Here is application's Heart</b></span>, update <b><i>goToNextView</i></b> method body this way</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 14px;">
<span style="color: black; font-family: Menlo; font-size: 11px;"> </span><b>-:-</b><span style="color: black; font-family: Menlo; font-size: 11px;"> </span><b>To Store Data in Preferences -:-</b></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextScreen:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *messageString = <span style="color: #4f8187;">messageTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSUserDefaults<span style="color: black;"> *prefs = [</span>NSUserDefaults<span style="color: black;"> </span><span style="color: #3d1d81;">standardUserDefaults</span><span style="color: black;">];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//save message into preferences </div>
<div style="font-family: Menlo; font-size: 11px;">
[prefs <span style="color: #3d1d81;">setObject</span>:messageString <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"MessageText"</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nextViewController<span style="color: black;"> = [[</span>NextViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">nextViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it, Save file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NSDefaultUserDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"NextViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nextViewController;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> messageTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"NSUserDefaults Demo"<span style="color: black;">;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextScreen:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *messageString = <span style="color: #4f8187;">messageTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSUserDefaults<span style="color: black;"> *prefs = [</span>NSUserDefaults<span style="color: black;"> </span><span style="color: #3d1d81;">standardUserDefaults</span><span style="color: black;">];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//save message into preferences </div>
<div style="font-family: Menlo; font-size: 11px;">
[prefs <span style="color: #3d1d81;">setObject</span>:messageString <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"MessageText"</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nextViewController<span style="color: black;"> = [[</span>NextViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">nextViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (NextViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure we already added one IBOutlet for UILabel in NextViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>NextViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NextViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NSDefaultUserDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> NextViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">weak</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #bb2ca2;">IBOutlet</span> <span style="color: #703daa;">UILabel</span> *receivedMessageLabel;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
now open its implementation file (NextViewController.m) file </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
1. in <b><i>viewDidLoad</i></b> method update its Title </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Result Screen"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. and get back the data from preferences</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 14px;">
<span style="color: black; font-family: Menlo; font-size: 11px;"> </span><b>-:-</b><span style="color: black; font-family: Menlo; font-size: 11px;"> </span><b>To Get Data from Preferences -:-</b></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
NSUserDefaults<span style="color: black;"> *prefs = [</span>NSUserDefaults<span style="color: black;"> </span><span style="color: #3d1d81;">standardUserDefaults</span><span style="color: black;">];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the message from preferences</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *messageStr = [prefs <span style="color: #3d1d81;">stringForKey</span>:<span style="color: #d12f1b;">@"MessageText"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #e32400; font-family: Menlo; font-size: 11px;">
<i>Note : make sure your key must be same as you defined while storing info</i></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. then show on label</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
receivedMessageLabel<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = messageStr;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>NextViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NextViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NSDefaultUserDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"NextViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>NextViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> NextViewController</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> receivedMessageLabel;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Result Screen"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSUserDefaults<span style="color: black;"> *prefs = [</span>NSUserDefaults<span style="color: black;"> </span><span style="color: #3d1d81;">standardUserDefaults</span><span style="color: black;">];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the message from preferences</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *messageStr = [prefs <span style="color: #3d1d81;">stringForKey</span>:<span style="color: #d12f1b;">@"MessageText"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//Note : make sure your key must be same as you defined while storing info</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>receivedMessageLabel<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = messageStr;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it --> enter any message</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8AND2dBoAYIKTs_J4Oh50uXIW_as_1mkAAXEfuQQZDlabl8sRkorZY6eIBGDDOEKkfyn_Jj55b2qE-a00cWl13DfhDMx5tvCBkzWatM1qaw0UGUGF8IqRSuKafCxfqQhXYAeUioUZXmgX/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8AND2dBoAYIKTs_J4Oh50uXIW_as_1mkAAXEfuQQZDlabl8sRkorZY6eIBGDDOEKkfyn_Jj55b2qE-a00cWl13DfhDMx5tvCBkzWatM1qaw0UGUGF8IqRSuKafCxfqQhXYAeUioUZXmgX/s320/Screen+8.png" width="222" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
press Next button and you can see the message stored and we get it back.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiRb2mYr3HIspLpuzyxCDauVnHEYmDYpMK-XdQr6on9Mz0nrln28QYfDUcqHcgG6JnU5eKKndPCWcPygwVjmo6W26F3cjVjdJlRPiAWeATNwEfNrspTdc5jCEjZ86dfvLQs0J6_u-R7HDO/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiRb2mYr3HIspLpuzyxCDauVnHEYmDYpMK-XdQr6on9Mz0nrln28QYfDUcqHcgG6JnU5eKKndPCWcPygwVjmo6W26F3cjVjdJlRPiAWeATNwEfNrspTdc5jCEjZ86dfvLQs0J6_u-R7HDO/s320/Screen+9.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! we did it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <span style="color: #38761d; font-size: 14px;"><a href="https://www.opendrive.com/files?M182Mjc5NzY1XzhpSGJl" target="_blank"><b>NSDefaultUserDemo.zip (82.63 KB)</b></a></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !!</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-41078365124437860032013-03-11T23:57:00.000-07:002013-03-11T23:57:00.392-07:00How to Add Navigation Controller in iPhone Application<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
This time we are going to learn How to add Navigation Controller in iPhone application</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
What is Navigation Controller in iPhone applications?</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; margin-bottom: 13px;">
A Navigation Controller is a special kind of view controller that manages a stack of view controllers and their corresponding views. It's an ideal way to display hierarchical data.</div>
<div style="font-family: Helvetica; font-size: 12px; margin-bottom: 13px;">
The Navigation Controller is always initialized with a root view controller; this will be the starting view at the bottom of the stack. As the user presses buttons in that view, you can then push a new view controller onto the stack to show a new view. When the user is done with the new view and presses a button to go back, you then pop that controller off the stack to return to the root view.</div>
<div style="font-family: Helvetica; font-size: 12px; margin-bottom: 13px;">
A Navigation Controller can be used with or without a Navigation Bar, which appears at the top of the screen:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaKMnxtrHgBC4sGYWYz1x6b12Vj0bcoFE_1JhXyCjc7FP6nX2LznselkyDMzn446vY1P4vlUxa221lu6QqRjo4pB5IQiOJdideabIceJ_ZPBnNEzDexKz1XlZMtAGeQIf5zD_gbNr-7m8F/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaKMnxtrHgBC4sGYWYz1x6b12Vj0bcoFE_1JhXyCjc7FP6nX2LznselkyDMzn446vY1P4vlUxa221lu6QqRjo4pB5IQiOJdideabIceJ_ZPBnNEzDexKz1XlZMtAGeQIf5zD_gbNr-7m8F/s320/Screen+0.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px; margin-bottom: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; margin-bottom: 13px;">
When you push a new view onto the stack, the Navigation Bar will automatically show a "back" button on the left side of the bar that will take the user back to the previous view.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6 , Xcode 4.6, and MAC OS X Lion 10.8.1</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you <b>Single View Application</b> templet as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>NavigationDemo<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
-------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1jrkHvwCaSWwXSIlo5gwMWONACChFOMvNvbsb4fb87LmOR-03h1AZoZFVRE4HT4VqPhNCrClm5P_befo1JilUYBr14n-n-NIuF-Ypu1DY2JKWPH1KV8-3RYBTAKGK3r8JMiZGSs7nPUyM/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1jrkHvwCaSWwXSIlo5gwMWONACChFOMvNvbsb4fb87LmOR-03h1AZoZFVRE4HT4VqPhNCrClm5P_befo1JilUYBr14n-n-NIuF-Ypu1DY2JKWPH1KV8-3RYBTAKGK3r8JMiZGSs7nPUyM/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Add more ViewControllers)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
we need to Add one more UIViewController for second screen. create and give name as "NextViewController" this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. File --> New --> File --> Select Objective -C class templet (in Cocoa Touch option).</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. In the next window give file details</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class : <b>NextViewController</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Subclass of : <b>UIViewController</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "<i>With XIB for user interface</i>" option --> Next -->create. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So for now our application project structure look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4tw-DvnXROX8zYdOyrUBGfVxQIzbha2B_3rr0rbfs7Gtj8sk8DFrp1-WoQBBu2t2gY5MVAikLPKMHxh4nadCKaKXsgTpwB6iabcfTehG2LMHKv-a_v4Buqcd6edFEWiL_9hAAqK_S4upI/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4tw-DvnXROX8zYdOyrUBGfVxQIzbha2B_3rr0rbfs7Gtj8sk8DFrp1-WoQBBu2t2gY5MVAikLPKMHxh4nadCKaKXsgTpwB6iabcfTehG2LMHKv-a_v4Buqcd6edFEWiL_9hAAqK_S4upI/s320/Screen+3.png" width="170" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br />
Open <b>ViewController.xib</b> file<br />
</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">1. </span>Select Layout --> go to attribute inspector --> change Top Bar value to NavigationBar.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjzGIR78jZehtWBp3NJmNhBtQdcBPv-WK4mkwctkqRQV9SbW9ho4PSCPsOsuG8R0wQUjH28sPwlyn00009f14hEskD86RSve9ttSOxKkDRPyRzPHPQhNR-RGt8P7F-zXWT7EWFHtWOdS2n/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="91" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjzGIR78jZehtWBp3NJmNhBtQdcBPv-WK4mkwctkqRQV9SbW9ho4PSCPsOsuG8R0wQUjH28sPwlyn00009f14hEskD86RSve9ttSOxKkDRPyRzPHPQhNR-RGt8P7F-zXWT7EWFHtWOdS2n/s320/Screen+4.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br />
2. drag UIButton from object library and double click on it, update name as "Next" --> save this file<br />
<div style="min-height: 14px;">
<br /></div>
3. change background color to <span style="color: #669c35;">Green</span><br />
<div style="min-height: 14px;">
<br /></div>
Now open <b>NextViewController.xib</b><br />
<div style="min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">4.</span>Select Layout --> go to attribute inspector --> change Top Bar value to NavigationBar.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
5. change background color to <span style="color: #5e30eb;">Blue</span><br />
</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBAction methods for UIButton .</div>
<div style="font-family: Helvetica; font-size: 12px;">
So just open ViewController.xib </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Create IBAction</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. select Scan Button -- > press Ctrl +Click and drag cursor between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span> (in Right side Header File). </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. in the pop up window make sure you change Connection type Outlet to --> <b>Action, </b>and give method name as "<i>goToNextView</i>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1D3Vtv681BaI9fKLDevhyphenhyphenW9xAYN2DoEGilv9I3PbVigPBAve8M7iJmAWAXmi6G0C2sPnuiA_DzxBaizPkTiFe9YIef9fVFJ5iyMv8ZSh6RbwJwClw-RUnINrKIuoBVEOA7PYONbB8Idqc/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1D3Vtv681BaI9fKLDevhyphenhyphenW9xAYN2DoEGilv9I3PbVigPBAve8M7iJmAWAXmi6G0C2sPnuiA_DzxBaizPkTiFe9YIef9fVFJ5iyMv8ZSh6RbwJwClw-RUnINrKIuoBVEOA7PYONbB8Idqc/s1600/Screen+5.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you will find one IBAction method is created in header file and empty body is added in implementation file (.m file ) too</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextView:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - V (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
To enable Navigation Controller in our application we need to add it in app delegate.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So open AppDelegate.h</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. create UINavigationController with strong property </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> *rootController;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> *rootController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to AppDelegate.m file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. in <span style="font-family: Menlo; font-size: 11px;">didFinishLaunchingWithOptions </span>method initialize Navigation Controller, by adding ViewController as a Root.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">rootController</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithRootViewController<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">viewController</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. add navigation controller to UIWindow</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>rootController<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">]; </span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">rootController</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UINavigationController</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithRootViewController<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">viewController</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>rootController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Open ViewController.h file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class</span> statement just below to <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#import </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>NextViewController<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. create strong property for NextViewController, We are going to load via Next Button</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">NextViewController</span> *nextViewController;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>NextViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">NextViewController</span> *nextViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextView:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now open ContactObject's implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.m</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nextViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. in <b>viewDidLoad</b> method put title for Current view</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Main View"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. update <b><i>goToNextView</i></b> method body this way</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextView:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nextViewController<span style="color: black;"> = [[</span>NextViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//we already added navigation controller in app delegate, so using that load new view</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">nextViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it, Save file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"NextViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nextViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">viewDidLoad</span>]; </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Main View"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goToNextView:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nextViewController<span style="color: black;"> = [[</span>NextViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//we already added navigation controller in app delegate, so using that load new view</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">nextViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (NextViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure we don't need to change anything in NextViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>NextViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NextViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> NextViewController : <span style="color: #4f8187;">ViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
now open its implementation file (NextViewController.m) file </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
in viewDidLoad method update its Title </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Second View"<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>NextViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NextViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// NavigationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/12/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"NextViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>NextViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> NextViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">viewDidLoad</span>]; </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Second View"<span style="color: black;">; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhroeIZng-KzXFgS3xny7YD_JNRy4P21eGtoA7PaN0FXG6Re7P_PrsQgRtrhtyDECKLgQt_2mEN-X-dDx6ey47dV2x4VDGixszQvw158rkbhFmb3jM6swA69XqE5X1yqo7HVfWi3VsGz6nd/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhroeIZng-KzXFgS3xny7YD_JNRy4P21eGtoA7PaN0FXG6Re7P_PrsQgRtrhtyDECKLgQt_2mEN-X-dDx6ey47dV2x4VDGixszQvw158rkbhFmb3jM6swA69XqE5X1yqo7HVfWi3VsGz6nd/s320/Screen+8.png" width="222" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
press Next button and you can see back button " MainView" is added by Navigation Controller.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCgE5nHN6F3Rw9G-OmqztgEBVVJ50dUTFmEdJCekGDtRR2bL8KqNbO_14h6Xgh_HzcraBGhs73kwZU6cws0phhchObFy1ENY0vT3djEvAmcaEi7VBcMfFK3TCk7r6o1Rj4odYcmYR69wS6/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCgE5nHN6F3Rw9G-OmqztgEBVVJ50dUTFmEdJCekGDtRR2bL8KqNbO_14h6Xgh_HzcraBGhs73kwZU6cws0phhchObFy1ENY0vT3djEvAmcaEi7VBcMfFK3TCk7r6o1Rj4odYcmYR69wS6/s320/Screen+9.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! we did it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <span style="background-color: white; font-size: 14px;"><a href="https://www.opendrive.com/files?M182Mjc0NzQ3Xzg2YzZ0" target="_blank"><b><span style="color: #38761d;">NavigationDemo.zip (75.14 KB)</span></b></a></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !!</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764152 76.949115699999979 13.466782199999999 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-39663080313194808762013-03-11T06:04:00.001-07:002013-03-11T06:17:10.420-07:00How to use Barcode Scanner (BR and QR) in iPhone Tutorial (using ZBar)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
What's up 01000101 developers!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Sitting on Rolling-Chair, Looking for good resources "How to use BarCode scanner in iPhone</div>
<div style="font-family: Helvetica; font-size: 12px;">
".. on IT's Lord <b>Google</b> and digging on <b>StackOverFlow</b>.. but still not sure How to implement Bar Code Scanner.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay just chill you are landed up here and I bet, after 20 minutes you will have your own application for Scanning bar codes :)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRyRxoKA_FsKIiEJdT9Ts63WSk1MSuL3htZaEmjH6yKqrggBQeycK-Ffur4eQr3uV6w9YbojlFiZ_pMSThRzE_lttxccRD5heePCt0nkKJ_WFw7JxMU1wMnqrS_5yk6ZvWr_vgVF3Zxpit/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRyRxoKA_FsKIiEJdT9Ts63WSk1MSuL3htZaEmjH6yKqrggBQeycK-Ffur4eQr3uV6w9YbojlFiZ_pMSThRzE_lttxccRD5heePCt0nkKJ_WFw7JxMU1wMnqrS_5yk6ZvWr_vgVF3Zxpit/s320/Screen+0.png" width="219" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
What is BarCode?</div>
<div style="font-family: Helvetica; font-size: 12px;">
There are two types of code scanner</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4d22b3; font-family: Helvetica; font-size: 12px;">
1. BR Code (Bar Code / 1D)</div>
<div style="color: #212121; font-family: Arial; font-size: 13px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">Google says "</span>A machine-readable code in the form of numbers and a pattern of parallel lines of varying widths, printed on and identifying a product.<span style="color: black; font-family: Helvetica; font-size: 12px;">"</span></div>
<div style="color: #212121; font-family: Arial; font-size: 13px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS1E1QEmcEFf7QFb80L4Cwfu2fZVCiTmskhX0I9yhp7rNBnqoapWPktvGi6DLNxt224PMXsaHOLJNNAG3QyTOSG1opjv70ilxPdYVygV9Csi4kfo-VzA4XnEuctkaMWEk2NOTJUJwfpcy2/s1600/barcode.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="143" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS1E1QEmcEFf7QFb80L4Cwfu2fZVCiTmskhX0I9yhp7rNBnqoapWPktvGi6DLNxt224PMXsaHOLJNNAG3QyTOSG1opjv70ilxPdYVygV9Csi4kfo-VzA4XnEuctkaMWEk2NOTJUJwfpcy2/s200/barcode.png" width="200" /></a></div>
<div style="color: #212121; font-family: Arial; font-size: 13px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;"><br /></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4d22b3; font-family: Helvetica; font-size: 13px;">
<span style="font-size: 12px;">2. QR Code (</span>Quick Response Code / 2D<span style="font-size: 12px;">)</span></div>
<div style="color: #212121; font-family: Arial; font-size: 13px;">
A QR Code is a matrix barcode (or two-dimensional code), readable by QR scanners, mobile phones with a camera, and smartphones.</div>
<div style="color: #212121; font-family: Arial; font-size: 13px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb5ZLVamKRtTQLnqx3pFOZxcx77zCrm0jGeggfh38bHDKT48uP6sscZkJX8bVJQAdspAGjYq7I2GpIBv-PNY_KwfrghBDNRN3z0S9ZjtYT4xHhWMNqrvR3-EaRke5BaovUf9YSJdCQ36Ty/s1600/qrcode.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb5ZLVamKRtTQLnqx3pFOZxcx77zCrm0jGeggfh38bHDKT48uP6sscZkJX8bVJQAdspAGjYq7I2GpIBv-PNY_KwfrghBDNRN3z0S9ZjtYT4xHhWMNqrvR3-EaRke5BaovUf9YSJdCQ36Ty/s1600/qrcode.png" /></a></div>
<div style="color: #212121; font-family: Arial; font-size: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So we are going to use ZBar SDK for BR and QR code scanning in our iPhone application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6 , Xcode 4.6, and MAC OS X Lion 10.8.1</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you <b>Single View Application</b> templet as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>BarCodeScannerDemo<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh67a4R6Mb0g9-j7HSLokrgq3pGK8NCOk6M2WzjyRjbbyptzdJjZ7u8JjSZyA6JW46Xwxpo_gtNFZbNoOW2EST-84eCLpg7TRBVBKLw3XqCG9S-U6EczUhGw7EFH7_8l6xSvU1vRWcv63mn/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh67a4R6Mb0g9-j7HSLokrgq3pGK8NCOk6M2WzjyRjbbyptzdJjZ7u8JjSZyA6JW46Xwxpo_gtNFZbNoOW2EST-84eCLpg7TRBVBKLw3XqCG9S-U6EczUhGw7EFH7_8l6xSvU1vRWcv63mn/s320/Screen+2.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Add Extra Frameworks/ Lib )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
to use the ZBar Scanner we need to add ZBar SDK to our Project.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br />
1. Download ZBar SDK I have uploaded <a href="https://www.opendrive.com/files?M182MjQ1NTQ1X3ZRWFFn" target="_blank"><b><span style="color: #38761d;">zip file here</span></b></a> also you can find latest SDK <span style="color: #be38f3;">dmg file</span> from official website <a href="http://sourceforge.net/projects/zbar/files/iPhoneSDK/ZBarSDK-1.2.dmg/download" target="_blank"><b><span style="color: #38761d;">here</span></b></a>.<br />
<div style="min-height: 14px;">
<br /></div>
2. Extract downloaded stuff, you can find <span style="color: #ffaa00;"><b>ZBarSDK </b></span>named folder inside it (which contains headers and resources files).<br />
<div style="min-height: 14px;">
<br /></div>
3. Drag the <span style="background-color: #ecf0f3;"><b>ZBarSDK</b></span> folder into your Xcode project, Make sure that the “<i>Copy Items into destination group’s folder</i>” checkbox is checked.<br />
<div style="min-height: 14px;">
<br /></div>
4. Now Select project (Blue Icon) go to --> Build Phases --> <span style="background-color: #ecf0f3;">Link Binary With Libraries</span>.<br />
Click the <span style="background-color: #ecf0f3;">+</span> and add each of these seven frameworks.<br />
<div style="min-height: 14px;">
<br /></div>
<ul>
<li style="margin: 0px; text-align: justify;"><i>AVFoundation.framework</i></li>
<li style="margin: 0px; text-align: justify;"><i>CoreGraphics.framework</i></li>
<li style="margin: 0px; text-align: justify;"><i>CoreMedia.framework</i></li>
<li style="margin: 0px; text-align: justify;"><i>CoreAudio.framework</i></li>
<li style="background-color: #fefdfa; color: #323333; font-family: Arial; font-size: 13px; margin: 0px; text-align: justify;"><i>CoreVideo.framework</i></li>
<li style="background-color: #fefdfa; color: #323333; font-family: Arial; font-size: 13px; margin: 0px; text-align: justify;"><i>QuartzCore.framework</i></li>
<li style="margin: 0px; text-align: justify;"><i>libiconv.dylib</i></li>
</ul>
<div style="margin-bottom: 3px; min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br /></div>
sometimes the order is important, you can see<b> libzbar.a</b> is at the bottom (it added auto when we dragged SDK)<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilOEiAGrLGer8uKXZwDlg5bCpoTEDiW5-gaXY6yrPaB1DFJ3Go5Q0imAXoRtIQakpKSIYAyE7xy5SezKp5Z7oSaU0HucibTfnNtbGgcCdEzmXJwUT3dCcJjur-SF8wzs7J05Z2sU1eTTvA/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="269" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilOEiAGrLGer8uKXZwDlg5bCpoTEDiW5-gaXY6yrPaB1DFJ3Go5Q0imAXoRtIQakpKSIYAyE7xy5SezKp5Z7oSaU0HucibTfnNtbGgcCdEzmXJwUT3dCcJjur-SF8wzs7J05Z2sU1eTTvA/s320/Screen+3.png" width="320" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
Now you can arrange the project structure as shown below.<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY5EoO7LMNOEY6lnQKDyXjqKOU9k9tQwURGNVtG9xb2UnM3ZL9qe40dMhEpXZTTmYqLhli4r8s9jOz5Evlpp42OH5XUH7GsQUgpf_Ywds-MqjxkedBIrH95lgmSfSq_N8cx3cIhB5zUvqp/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY5EoO7LMNOEY6lnQKDyXjqKOU9k9tQwURGNVtG9xb2UnM3ZL9qe40dMhEpXZTTmYqLhli4r8s9jOz5Evlpp42OH5XUH7GsQUgpf_Ywds-MqjxkedBIrH95lgmSfSq_N8cx3cIhB5zUvqp/s320/Screen+4.png" width="153" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
<b>PHASE - III (Design UI)</b><br />
<div style="min-height: 14px;">
<b></b><br /></div>
Open ViewController.xib file<br />
<div style="min-height: 14px;">
<br /></div>
1. drag UIImage View from object lib and resize it as given screen shot<br />
2. add one UILabel just below to ImageView and double click on it and put "Scan Result is :"<br />
3. now drag UITextView and resize it like ImageView, double click and write "No bar code scanned.."<br />
4. finally add one UIButton view and give it name as "Scan"<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlgx5TTGV6SP-8e6VBsOxQ7knlYlhC5O8LFgZPmJMDtAed0G7qNyKvcSCa1r326gcWlesd8IpCKLfIyNQBh_iFOXMCYABoIpXnUzeryBw7F3qTdJXRtkZg74dw_IUkDOOCNkXPo_x3h91m/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlgx5TTGV6SP-8e6VBsOxQ7knlYlhC5O8LFgZPmJMDtAed0G7qNyKvcSCa1r326gcWlesd8IpCKLfIyNQBh_iFOXMCYABoIpXnUzeryBw7F3qTdJXRtkZg74dw_IUkDOOCNkXPo_x3h91m/s320/Screen+5.png" width="222" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
<b>PHASE - IV (Create IBOutlets and IBAction )</b><br />
<div style="min-height: 14px;">
<b></b><br /></div>
We are going to create IBOutlet for UIImageView and UILabel and IBAction methods for UIButton .<br />
So just open ViewController.xib<br />
<div style="min-height: 14px;">
<br /></div>
Okay, Now select Assistant Editor on Top Right side<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.<br />
<div style="min-height: 14px;">
<br /></div>
<b>Create IBOutlet</b><br />
<div style="min-height: 14px;">
<br /></div>
1. select ImageView -- > press Ctrl +Click and drag cursor between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span> (in Right side Header File).<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj72fCytjjE31PlKoJoJuPWrJgLMDjNfxgOwlC-E9cXpbV7KgFoVE33e3WR_k-ptNFH3zdtSH_Yerw-Aufu-T7qq4OvgAhAWnE-8IkYoMCgjwa17WAaL1aHG6kIo1SsKlrR7odayzdfCrOz/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj72fCytjjE31PlKoJoJuPWrJgLMDjNfxgOwlC-E9cXpbV7KgFoVE33e3WR_k-ptNFH3zdtSH_Yerw-Aufu-T7qq4OvgAhAWnE-8IkYoMCgjwa17WAaL1aHG6kIo1SsKlrR7odayzdfCrOz/s320/Screen+7.png" width="320" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
2. in the pop up window, put name as "resultImageView" and connect.<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_jOxPQLwmGdDgGQOR6j0414CgQNm4XHqGRCadU5hRfj839qopXdo8kNbzsK2bTLgq3xyoeNzXdHmrYNgdjqNFp6LRblfIOX0J3K3Cad02ZtGBi3f_Pv059m30KbqLvo1pDWyBSD59T2mR/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_jOxPQLwmGdDgGQOR6j0414CgQNm4XHqGRCadU5hRfj839qopXdo8kNbzsK2bTLgq3xyoeNzXdHmrYNgdjqNFp6LRblfIOX0J3K3Cad02ZtGBi3f_Pv059m30KbqLvo1pDWyBSD59T2mR/s1600/Screen+8.png" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
you can see below line is added in ViewController.h file<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIImageView</span><span style="color: black;"> *resultImageView;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
do the same for UITextView and give name as "resultTextView"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
below line will added in header file</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextView</span><span style="color: black;"> *resultTextView;</span></div>
<div style="min-height: 14px;">
<br /></div>
<b>Create IBAction</b><br />
<div style="min-height: 14px;">
<br /></div>
3. select Scan Button and Ctrl +Click and drag Cursor below to to IBOutlets created.<br />
<div style="min-height: 14px;">
<br /></div>
4. in the pop up window <span style="color: red;">make sure you change Connection type Outlet to --> </span><b><span style="color: red;">Action,</span> </b>and give method name as "<i>startScanning</i>"<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXxDrNlxD_QEYOm2il5i2rITQVb7GfeN3hgBsRc1wO1FzGy2papVR_JLlyclNK4tpEQScKEkyOwQlY-Cov_mAuRF5mvyy_W-BDDfBbNJAOz8txIClJS5xkLXE4-tSebp4TF2fYu29LnA43/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXxDrNlxD_QEYOm2il5i2rITQVb7GfeN3hgBsRc1wO1FzGy2papVR_JLlyclNK4tpEQScKEkyOwQlY-Cov_mAuRF5mvyy_W-BDDfBbNJAOz8txIClJS5xkLXE4-tSebp4TF2fYu29LnA43/s1600/Screen+9.png" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
you will find one IBAction method is created in header file and empty body is added in implementation file (.m file ) too<br />
<div style="min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startScanning:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br /></div>
Done!! now back to Standard Editor<br />
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br /></div>
<b>PHASE - V (Writing Code)</b><br />
<div style="min-height: 14px;">
<b></b><br /></div>
<div style="min-height: 14px;">
<b></b><br /></div>
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b><br />
<div style="min-height: 14px;">
<b></b><br /></div>
Open ViewController.h file<br />
<div style="min-height: 14px;">
<br /></div>
1. add <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#import </span> statement<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ZBarSDK.h"</div>
<div style="min-height: 14px;">
<br /></div>
2. add ZBar Delegate, we are going to use its delegates methods<br />
<div style="min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span> <<span style="color: #4f8187;">ZBarReaderDelegate</span>></div>
<div style="min-height: 14px;">
<br /></div>
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// BarCodeScannerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ZBarSDK.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span><<span style="color: #4f8187;">ZBarReaderDelegate</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIImageView</span><span style="color: black;"> *resultImageView;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextView</span><span style="color: black;"> *resultTextView;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startScanning:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
now open ContactObject's implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">ViewController.m</span><br />
<div style="color: #008400; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span><br />
<div style="min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultImageView;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultTextView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. Now <span style="color: #e32400;"><b>Here is application's Heart</b></span>, update <b><i>startScanning</i></b> method body this way</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startScanning:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Scanning.."<span style="color: black;">); </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>resultTextView<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = </span><span style="color: #d12f1b;">@"Scanning.."</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>ZBarReaderViewController<span style="color: black;"> *codeReader = [</span>ZBarReaderViewController<span style="color: black;"> </span><span style="color: #3d1d81;">new</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
codeReader.<span style="color: #4f8187;">readerDelegate</span>=<span style="color: #bb2ca2;">self</span>;</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> codeReader.</span>supportedOrientationsMask<span style="color: black;"> = </span><span style="color: #78492a;">ZBarOrientationMaskAll</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">ZBarImageScanner</span> *scanner = codeReader.<span style="color: #4f8187;">scanner</span>;</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [scanner </span>setSymbology<span style="color: black;">: </span>ZBAR_I25<span style="color: black;"> </span>config<span style="color: black;">: </span>ZBAR_CFG_ENABLE<span style="color: black;"> </span>to<span style="color: black;">: </span><span style="color: #272ad8;">0</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>presentViewController<span style="color: black;">:codeReader </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. Implement ZBar's Delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>) imagePickerController: (<span style="color: #703daa;">UIImagePickerController</span>*) reader didFinishPickingMediaWithInfo: (<span style="color: #703daa;">NSDictionary</span>*) info</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// get the decode results</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">id</span><<span style="color: #703daa;">NSFastEnumeration</span>> results = [info <span style="color: #3d1d81;">objectForKey</span>: <span style="color: #4f8187;">ZBarReaderControllerResults</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">ZBarSymbol</span> *symbol = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span>(symbol <span style="color: #bb2ca2;">in</span> results)</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// just grab the first barcode</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">break</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// showing the result on textview</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">resultTextView</span>.<span style="color: #703daa;">text</span> = symbol.<span style="color: #4f8187;">data</span>; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">resultImageView</span><span style="color: black;">.</span>image<span style="color: black;"> = [info </span><span style="color: #3d1d81;">objectForKey</span><span style="color: black;">: </span>UIImagePickerControllerOriginalImage<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// dismiss the controller </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [reader </span>dismissViewControllerAnimated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="min-height: 14px;">
<br /></div>
That's it, Save file.<br />
<div style="min-height: 14px;">
<br /></div>
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// BarCodeScannerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultImageView;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultTextView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's LifeCycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button click method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startScanning:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Scanning.."<span style="color: black;">); </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>resultTextView<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = </span><span style="color: #d12f1b;">@"Scanning.."</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>ZBarReaderViewController<span style="color: black;"> *codeReader = [</span>ZBarReaderViewController<span style="color: black;"> </span><span style="color: #3d1d81;">new</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
codeReader.<span style="color: #4f8187;">readerDelegate</span>=<span style="color: #bb2ca2;">self</span>;</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> codeReader.</span>supportedOrientationsMask<span style="color: black;"> = </span><span style="color: #78492a;">ZBarOrientationMaskAll</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">ZBarImageScanner</span> *scanner = codeReader.<span style="color: #4f8187;">scanner</span>;</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [scanner </span>setSymbology<span style="color: black;">: </span>ZBAR_I25<span style="color: black;"> </span>config<span style="color: black;">: </span>ZBAR_CFG_ENABLE<span style="color: black;"> </span>to<span style="color: black;">: </span><span style="color: #272ad8;">0</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>presentViewController<span style="color: black;">:codeReader </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ZBar's Delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>) imagePickerController: (<span style="color: #703daa;">UIImagePickerController</span>*) reader didFinishPickingMediaWithInfo: (<span style="color: #703daa;">NSDictionary</span>*) info</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// get the decode results</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">id</span><<span style="color: #703daa;">NSFastEnumeration</span>> results = [info <span style="color: #3d1d81;">objectForKey</span>: <span style="color: #4f8187;">ZBarReaderControllerResults</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">ZBarSymbol</span> *symbol = <span style="color: #bb2ca2;">nil</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span>(symbol <span style="color: #bb2ca2;">in</span> results)</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// just grab the first barcode</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">break</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// showing the result on textview</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">resultTextView</span>.<span style="color: #703daa;">text</span> = symbol.<span style="color: #4f8187;">data</span>; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">resultImageView</span><span style="color: black;">.</span>image<span style="color: black;"> = [info </span><span style="color: #3d1d81;">objectForKey</span><span style="color: black;">: </span>UIImagePickerControllerOriginalImage<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// dismiss the controller </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [reader </span>dismissViewControllerAnimated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br /></div>
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b><br />
<div style="min-height: 14px;">
<br /></div>
Make sure your AppDelegate file code should be default<br />
<div style="min-height: 14px;">
<br /></div>
Finally our <b>AppDelegate.h</b> file look like<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// BarCodeScannerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br /></div>
Finally our <b>AppDelegate.m</b> file look like<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// BarCodeScannerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/11/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="min-height: 14px;">
<br /></div>
Okay wrap it up this application. let's Run it.<br />
<div style="min-height: 14px;">
<br /></div>
1. for BR Code<br />
<div style="min-height: 14px;">
<br /></div>
click on <b>Scan</b> Button --> Look for any Book have BarCode or you can create Barcode online<a href="http://www.barcode-generator.org/" target="_blank"> here</a> -- > zoom on it.<br />
<div style="min-height: 14px;">
<i></i><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSNpEyCuPo8W1d8mI4SwQfY57vuk4gOYPzD6NtHowZN7gTNs8MfuS7Yx907nypjaXPE3NHTFxECvo0yK42kYScxyZTZyg1_K7z5245xKFzfbiq0jYXAwB24K1_-NfJGBqtE0QQEOQjlwoS/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSNpEyCuPo8W1d8mI4SwQfY57vuk4gOYPzD6NtHowZN7gTNs8MfuS7Yx907nypjaXPE3NHTFxECvo0yK42kYScxyZTZyg1_K7z5245xKFzfbiq0jYXAwB24K1_-NfJGBqtE0QQEOQjlwoS/s320/Screen+11.png" width="222" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
2. for QR code<br />
<div style="min-height: 14px;">
<br /></div>
same way click on Button --> create your QR code online <b><span style="color: #38761d;"><a href="http://goqr.me/" target="_blank">here</a> </span></b>--> zoom on it --> see the result.<br />
<div style="color: #e32400;">
<i>Note : when it successfully read the code you can see</i><span style="color: black;"><i> </i></span><span style="color: #4f7a28;"><i>Green Frame</i></span><span style="color: black;"><i>.</i></span></div>
<div style="min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmzrN0b0lZKuGnKug67woie3hT20uuY5t_Q54u3idBrOutP4BbYcETMva98tEe1WfZot1yW6W-N9uZ_iTE0BAqR7VFa13JSsW8bmdYJAKRw7F-aiyXPZkhbD1kWyhIxVtC6AOuXA-O7k4/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmzrN0b0lZKuGnKug67woie3hT20uuY5t_Q54u3idBrOutP4BbYcETMva98tEe1WfZot1yW6W-N9uZ_iTE0BAqR7VFa13JSsW8bmdYJAKRw7F-aiyXPZkhbD1kWyhIxVtC6AOuXA-O7k4/s320/Screen+12.png" width="215" /></a></div>
<br />
<div style="min-height: 14px;">
<br /></div>
Wow!! we did it. and Credit goes to you.. just before Half an hour you started it now you can write any app for scanning Bar codes in iOS.<br />
<div style="min-height: 14px;">
<br /></div>
You can find complete project source code zip file here : <span style="font-size: 14px;"><a href="https://www.opendrive.com/files?M182MjQ1NTYzX1dNR2xZ" target="_blank"><b><span style="color: #38761d;">BarCodeScannerDemo.zip (2.69 MB)</span></b></a></span><br />
<div style="min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br /></div>
I Would love to here your thoughts !!</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com5Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-91089229487987566312013-03-08T00:53:00.002-08:002013-03-08T00:53:50.911-08:00SQLIte in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Starry Starry Night, I can feel the Glory of Moon which is looking at me from my Window.. :)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Enjoying Punk Rock "<span style="font-family: Arial; font-size: 13px;"><b>Boulevard Of Broken Dreams</b></span>" and I am going to write one more Article</div>
<div style="font-family: Helvetica; font-size: 12px;">
about one of the important key feature in iOS.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
How to use SQLite Database in our iPhone application with Insert, Select, Search and Delete operation programmatically?</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGGJzmiR4aWEN5jcA5oSubc0hVTtODW9uqlcKCfOwaf0Mn58svFdtVxX5R72BujeyF1Clw8OxZ0Bkj2MhzLRrFiKdnOyQ_tlz1YKQYTf47LZqbROj6T179GlXnK0i2p-ROSGe4cN3Qm2x9/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGGJzmiR4aWEN5jcA5oSubc0hVTtODW9uqlcKCfOwaf0Mn58svFdtVxX5R72BujeyF1Clw8OxZ0Bkj2MhzLRrFiKdnOyQ_tlz1YKQYTf47LZqbROj6T179GlXnK0i2p-ROSGe4cN3Qm2x9/s320/Screen+0.png" width="163" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #7b219f; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Before starting You may like to know our Database details</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span style="color: #008400;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Database Name : </span>contacts.db |</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;">|</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Database Table Name : <span style="color: black;">CONTACTS |</span></div>
<div style="font-family: Menlo; font-size: 11px;">
|<span style="color: #008400;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Table Columns Name : </span>NAME, ADDRESS, PHONE |</div>
<div style="font-family: Menlo; font-size: 11px;">
-------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
iPhone Simulator Sqlite DB file you can find on this path</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<b>/Users/RDCMac/Library/Application Support/iPhone Simulator/6.1/Applications/0975F545-E4D2-40E8-97C6-0EA7F8995315/Documents/contacts.db</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6 , Xcode 4.6, and MAC OS X Lion 10.8.1</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
---------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>SQLiteDemo<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXnBsMcSVqOdCqJrTAa3PoIU7gY62wrjNBkzP6ZJ-ZmJJKEzk-Mic5u4zULGqLfal8pD7nwC3g8Ebxc6FDYNcyC2MmQYgCYo3qkKpxc2GzJhaaHfthGTMTtBDBdQFHbZ5ST4dENA0hrYnm/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="264" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXnBsMcSVqOdCqJrTAa3PoIU7gY62wrjNBkzP6ZJ-ZmJJKEzk-Mic5u4zULGqLfal8pD7nwC3g8Ebxc6FDYNcyC2MmQYgCYo3qkKpxc2GzJhaaHfthGTMTtBDBdQFHbZ5ST4dENA0hrYnm/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Add Extra Frameworks/ Lib and Create required Files)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
to use the Sqlite database we need to add Sqlite Lib to our Project.</div>
<div style="font-family: Helvetica; font-size: 12px;">
procedure is same as we add framework to our project.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. select Project (Blue Icon) go to --> Build Phased --> <b>Link Binary With Libraries</b> option --> click (+) and you will get popup window, so look for "<span style="color: #0056d6;">libsqlite3.dylib </span>file".</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ17hay3GkvVWpVCNNXvOrs2bhywTWgs2_jwsZw8YiRkc_4YYivWNwMizWeW2PGpeElXBhSPIZiq2HYilSQmFchL5KebDK-heMdXW_yWx_6I338Rqsu3bPqkh10m4Y-RIMZMX_F2VMo7WV/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ17hay3GkvVWpVCNNXvOrs2bhywTWgs2_jwsZw8YiRkc_4YYivWNwMizWeW2PGpeElXBhSPIZiq2HYilSQmFchL5KebDK-heMdXW_yWx_6I338Rqsu3bPqkh10m4Y-RIMZMX_F2VMo7WV/s320/Screen+3.png" width="303" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
after adding successful you can see like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxKKqfhIqtq4FG10xLketQVc06w0vvgXo1UJuGYemPcfgMgmiv7k15unsygzkb_p8KxneBJcX4vId5o5P6jFZHAFejcsPxo7TWMskc8PQyfjR_-acaQvhyphenhyphenlGu5ShEiRdxpsCQchhS29w1U/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="177" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxKKqfhIqtq4FG10xLketQVc06w0vvgXo1UJuGYemPcfgMgmiv7k15unsygzkb_p8KxneBJcX4vId5o5P6jFZHAFejcsPxo7TWMskc8PQyfjR_-acaQvhyphenhyphenlGu5ShEiRdxpsCQchhS29w1U/s320/Screen+4.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see <span style="color: #0056d6;">ibsqlite3.dylib</span> file added to our project, drag this newly added file to the Frameworks folder,</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Now We will create two Important Classes </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
*Model Class for storing our object</div>
<div style="font-family: Helvetica; font-size: 12px;">
*DBHelper Class for Writing all SQLite Code in a single file, so we can use in whole app.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So first create two Groups/Folders for storing these classes.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. For Model Classes</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Create new group : Right click on project -->New Group</div>
<div style="font-family: Helvetica; font-size: 12px;">
new you can see new folder has been created, double click on it give name as "<span style="color: #4f7a28;">Models</span>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 Create Model Class to store <span style="text-decoration: underline;">Contact Object </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2.1 Right Click on <span style="color: #4f7a28;">Models</span> folder -->New File</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>in the pop window select "<b>Objective-C class</b>" Templet in <span style="color: #61177c;">Cocoa Touch</span> for iOS option.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s320/Screen+7.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2.2 In the next window Fill the values as written below</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>Class : <b>ContactObject</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>Subclass of : <b>NSObject</b> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #b51a00;">Note</span> : Un -check both checkboxes if they are checked (we don't need any XIB here)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjviWpWh_frrUYf6RRZjX96cGLlttLLs5FTs_NJU3Ou_IfNyM9y14knvoG2HK5hTGLT95tFdg1bBNOxoYeVfcz4gjt2bC_Ce2B4g9atr1Arx9zbTU5PdIWTJAgY363t9nLkJ7R3cIUidzRX/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjviWpWh_frrUYf6RRZjX96cGLlttLLs5FTs_NJU3Ou_IfNyM9y14knvoG2HK5hTGLT95tFdg1bBNOxoYeVfcz4gjt2bC_Ce2B4g9atr1Arx9zbTU5PdIWTJAgY363t9nLkJ7R3cIUidzRX/s320/Screen+6.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
then go for create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now we can see two new files added to our project</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
ContactObject.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
ContactObject.m</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. For DBHelper Class (procedure is same as we created Model class)</div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 Create new group : Right click on project -->New Group</div>
<div style="font-family: Helvetica; font-size: 12px;">
new you can see new folder has been created, double click on it give name as "<span style="color: #4f7a28;">DBHelper</span>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 Create Helper Class to handle all SQL code<span style="text-decoration: underline;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2.1 Right Click on <span style="color: #4f7a28;">DBHelper</span> folder -->New File</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>in the pop window select "<b>Objective-C class</b>" Templet in <span style="color: #61177c;">Cocoa Touch</span> for iOS option.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s320/Screen+7.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2.2 In the next window Fill the values as written below</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>Class : <b>DBHelper</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>Subclass of : <b>NSObject</b> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #b51a00;">Note</span> : Un -check both checkboxes if they are checked (we don't need any XIB here)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQGplLi75SdlMSTzP4_mEHsjiaMzMTahX1ZKAepzMtE4FMy4qUF2trIJf6M9uIXpvgoaDzKyGtYNYsyz6hMcGbRfiJZlSTcMn7zh7cSH6Sr9L0Hfi-TK-TfZbn7h_55LqCkTI_AUthyldS/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQGplLi75SdlMSTzP4_mEHsjiaMzMTahX1ZKAepzMtE4FMy4qUF2trIJf6M9uIXpvgoaDzKyGtYNYsyz6hMcGbRfiJZlSTcMn7zh7cSH6Sr9L0Hfi-TK-TfZbn7h_55LqCkTI_AUthyldS/s320/Screen+8.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
then go for create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now we can see two new files added to our project</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
DBHelper.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
DBHelper.m</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, this time our project structure is look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgdl7a4uLv7XW07i5noVRRzBPmybX9bXX4wSjoziOJabtn9fHi2yfJd8qNWSPTI5U45sJk5ub-CbP4iJBrH2BHqF2XUge3EInAoHy950TfJxgjcg-Gk7GHkinfLqRgrV1H9lCCmYkbC5-g/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgdl7a4uLv7XW07i5noVRRzBPmybX9bXX4wSjoziOJabtn9fHi2yfJd8qNWSPTI5U45sJk5ub-CbP4iJBrH2BHqF2XUge3EInAoHy950TfJxgjcg-Gk7GHkinfLqRgrV1H9lCCmYkbC5-g/s320/Screen+9.png" width="140" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add some UITextFields, UIButtons,UILabel and Title Bar on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. let's drag UINavigationBar from Object library double click on it and give title as "SQLite DB : Contact Info", (we will use this for just showing app Title)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. TextFields : </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2.1 now drag TextFields for Taking input <b>Name</b> ,adjust full width, then go to <b>Attribute <span class="Apple-tab-span" style="white-space: pre;"> </span>Inspector </b>and update Placeholder value as "enter name here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2.2 do same for next TextField for Taking input <b>Address</b> and change its Placeholder value as <span class="Apple-tab-span" style="white-space: pre;"> </span>"enter <span class="Apple-tab-span" style="white-space: pre;"> </span>address here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2.3. drag one more TextField for Taking input <b>Phone No</b> and change its Placeholder value as <span class="Apple-tab-span" style="white-space: pre;"> </span>"enter 10 digit phone no" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. UILabel : drag one label and double click on it, change text as "Note : for search and delete only enter name"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. UIButtons: drag 4 Buttons and double click and give them name as <b>Save</b>, <b>View All</b>, <b>Search</b>, and <b>Delete</b> respectively .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now adjust all these items on your Layout as per shown in below screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg8A531VJbWf8Uz79shninJI9XWPs7OpL9rFN-rti8P8r4wxBer-8JQaLICXFlZBCsyKwpxCAMYpXWVhXVQpcRP-gDdwBo1ujsdOsvzgUBcpEpR9u2hw9Ygf6oXRE-OeKIkC25F84SdOJP/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg8A531VJbWf8Uz79shninJI9XWPs7OpL9rFN-rti8P8r4wxBer-8JQaLICXFlZBCsyKwpxCAMYpXWVhXVQpcRP-gDdwBo1ujsdOsvzgUBcpEpR9u2hw9Ygf6oXRE-OeKIkC25F84SdOJP/s320/Screen+10.png" width="224" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UITextFields and IBAction methods for UIButtons .</div>
<div style="font-family: Helvetica; font-size: 12px;">
So just open ViewController.xib </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Create IBOutlets</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Select UITextField (which says - 'enter name here') --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe2625rDyd2eMX6ObeBPg24zS3nguJ7kCxQh6cBw-m949dTNH0Z1WSijqGronLlYbdtW9nU5XJIiZYq1WZVutdekjJ4os0IbKjyOSmpDSDwkShaf2RBwG8gnDuuLopAAWdsItmSS82sIw5/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe2625rDyd2eMX6ObeBPg24zS3nguJ7kCxQh6cBw-m949dTNH0Z1WSijqGronLlYbdtW9nU5XJIiZYq1WZVutdekjJ4os0IbKjyOSmpDSDwkShaf2RBwG8gnDuuLopAAWdsItmSS82sIw5/s320/Screen+12.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.3 Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">nameTextField</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqHJnF-TlH5hMadcHpu4xEum1Qj6JNPzdGHHl7ZCvup5ggK5J2bpAQ8ZfeuNtwdO8rhID2KmEMst8SvLJ73GTWhWRQ2ch0lXpdnLjfZPYT3BkcabkD5VbleanOoROE4S2yM1BloEP_5Qdo/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="99" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqHJnF-TlH5hMadcHpu4xEum1Qj6JNPzdGHHl7ZCvup5ggK5J2bpAQ8ZfeuNtwdO8rhID2KmEMst8SvLJ73GTWhWRQ2ch0lXpdnLjfZPYT3BkcabkD5VbleanOoROE4S2yM1BloEP_5Qdo/s320/Screen+13.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see below line added in our ViewController's header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *nameTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
1.4 do the same for next two TextFields and give them name as "addressTextField" and "phoneNoTextField" respectively </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time you can see two IBOutlets created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *addressTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *phoneNoTextField;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Create IBAction methods</div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 Select UIButton (which says -'Save') --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 Click on <span style="color: #4f7a28;"><b>Touchup Inside</b></span> in "Sent Events" option and drag cursor just below to new created IBOutlets, and put the method name "" in pop window</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4a1nroAuQKpIJEwG44UxGNqEHVhyphenhyphenzA34lFF_M5PZMHDVSpj8hgg72F-1F5HEIE2YdflPqxkhIOmp8b3mmwKeUAM0MdbUB6X-TmH11-YgpOWPg_ag9faIJa85z_K-A7DkR1V3n2J2boKz2/s1600/Screen+14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4a1nroAuQKpIJEwG44UxGNqEHVhyphenhyphenzA34lFF_M5PZMHDVSpj8hgg72F-1F5HEIE2YdflPqxkhIOmp8b3mmwKeUAM0MdbUB6X-TmH11-YgpOWPg_ag9faIJa85z_K-A7DkR1V3n2J2boKz2/s1600/Screen+14.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see new method is added in our ViewController's header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.3 do the same for next three Buttons and give methods name as "viewAllContactsInfo","searchContactInfo" and "deleteContactInfo" respectively.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time you can see three new IBAction methods created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Hook Up Delegate with File Owner )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here we need to hook up our TextFields Delegate to File Owner, so we can use its method to hand Keypad.</div>
<div style="font-family: Helvetica; font-size: 12px;">
when use Tap Return key while typing then keypad should go back.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Open ViewController.xib</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select UITextField (which says - 'enter name here') --> go the Connection Inspector --> drag cursor from Delegate to File owner (Right to Left)</div>
<div style="font-family: Helvetica; font-size: 12px;">
as shown in below screen shot</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiELw2tMuhbcFnbAegF1_g3Hlus_QS9lZahfagqz-lvYqKvcgzW3xRY3lYCmBl22RlBfE53gDkxZ4aRR8UFKr422Nfq44XwZiWErDFa14f9iCuH8SRzKh_0xQMCDVEBMgRlFW_1hKKgk8n3/s1600/Screen+16.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="253" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiELw2tMuhbcFnbAegF1_g3Hlus_QS9lZahfagqz-lvYqKvcgzW3xRY3lYCmBl22RlBfE53gDkxZ4aRR8UFKr422Nfq44XwZiWErDFa14f9iCuH8SRzKh_0xQMCDVEBMgRlFW_1hKKgk8n3/s320/Screen+16.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. repeat same for next two Text Fields (Address, Phone No)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #e32400;"><i>Note</i></span><i> : you can achieve same by doing it programmatically in ViewController's </i><b><i>viewDidLoad</i></b><i> method.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
nameTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> =</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
addressTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;">=</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;">=</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - V (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ MODEL Class (ContactObject) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
First is First!, We will pull data from Database table and put into Our Model Class (Object Class) and then in the Controller we will get it from Model and show with UI.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Save application, and open <span style="color: #008400; font-family: Menlo; font-size: 11px;">ContactObject.h</span> file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">1. declare variables with </span><span style="color: #bb2ca2;">@property </span>to store ContactObject's data</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *name;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *address;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *phoneNO;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">2. </span>declare init method to initialize our ContactObject</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">id</span>)initContactObjectByName:(<span style="color: #703daa;">NSString</span> *)cName Address:(<span style="color: #703daa;">NSString</span> *)cAddress PhoneNo:(<span style="color: #703daa;">NSString</span> *)cPhoneNo;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ContactObject.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ContactObject.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ContactObject : <span style="color: #703daa;">NSObject</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Variables to hold the data of ContactObject.</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *name;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *address;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">,</span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *phoneNO;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//Method Declaration to initialize the ContactObject.</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">id</span>)initContactObjectByName:(<span style="color: #703daa;">NSString</span> *)cName Address:(<span style="color: #703daa;">NSString</span> *)cAddress PhoneNo:(<span style="color: #703daa;">NSString</span> *)cPhoneNo;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now open ContactObject's implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">ContactObject.m</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> address;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> phoneNO;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. update init method body</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">id</span>) initContactObjectByName:(<span style="color: #703daa;">NSString</span> *)cName Address:(<span style="color: #703daa;">NSString</span> *)cAddress PhoneNo:(<span style="color: #703daa;">NSString</span> *)cPhoneNo{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span> = [<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">name</span> = cName;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">address</span> = cAddress;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">phoneNO</span> = cPhoneNo;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>self<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">}</span> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ContactObject.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ContactObject.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ContactObject.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> ContactObject</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> address;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> phoneNO;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">id</span>) initContactObjectByName:(<span style="color: #703daa;">NSString</span> *)cName Address:(<span style="color: #703daa;">NSString</span> *)cAddress PhoneNo:(<span style="color: #703daa;">NSString</span> *)cPhoneNo{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span> = [<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">name</span> = cName;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">address</span> = cAddress;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">phoneNO</span> = cPhoneNo;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>self<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ HELPER Class (DBHelper) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
It's time to write <span style="color: #b51a00;">Heart of the Application</span>. we will write the code :-</div>
<div style="font-family: Helvetica; font-size: 12px;">
* how to create New Database, Table, and then store data, search item, delete etc.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, tight your seatbelt, we are going for iDrive.. ;)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">open your </span><span style="color: #008400;">DBHelper.h </span>class<span style="font-family: Helvetica; font-size: 12px;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. do you remember we added Sqlite lib to our project, time to import that here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><sqlite3.h></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. also we will use model class here so add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class </span>just below to <span style="color: #78492a; font-family: Menlo; font-size: 11px;">import </span>statement .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ContactObject<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. create instance variables for Sqlite class and String for Database file path.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
sqlite3<span style="color: black;"> *db;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *databasePath;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
4. declare static method to initialize our database</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">DBHelper</span> *)initializeDatabase;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
5. declare instance methods for Insert, Search, delete and select all contacts info.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName :(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #4f8187;">ContactObject</span> *) searchContactInfoByName :(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>DBHelper.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DBHelper.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><sqlite3.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ContactObject<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> DBHelper : <span style="color: #703daa;">NSObject</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3</span> *db;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *databasePath;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">DBHelper</span> *)initializeDatabase;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName :(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #4f8187;">ContactObject</span> *) searchContactInfoByName :(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *) name;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Bravo!! Bravo!!.. keep moving like a RockStar \m/</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
open DBHelper's implementation class <span style="color: #008400; font-family: Menlo; font-size: 11px;">DBHelper.m</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add <span style="color: #78492a; font-family: Menlo; font-size: 11px;">import </span>statement for our model class because in header file just added <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class</span><span style="font-family: Menlo; font-size: 11px;"> </span>only</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ContactObject.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. declare static variable for DBHelper</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #4f8187;">DBHelper</span> *dbHelper;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. write the body for initialize method </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">DBHelper</span> *)initializeDatabase{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">dbHelper</span> == <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>//init method's body we will provide below</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">dbHelper</span> = [[<span style="color: #4f8187;">DBHelper</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>dbHelper<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">id</span>) init{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span> = [<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #bb2ca2;">self</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>createDatabase<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>self<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
4. now here is the method to Create new Database and Table</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) createDatabase {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *dirPaths;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *docsDirPath;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Get the documents directory</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> dirPaths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
docsDirPath = [dirPaths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Build the path to the database file</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithString<span style="color: black;">: [docsDirPath </span>stringByAppendingPathComponent<span style="color: black;">: </span><span style="color: #d12f1b;">@"contacts.db"</span><span style="color: black;">]];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"database path is : %@"<span style="color: black;">,</span><span style="color: #4f8187;">databasePath</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//Now create the database</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSFileManager<span style="color: black;"> *filemgr = [</span>NSFileManager<span style="color: black;"> </span><span style="color: #3d1d81;">defaultManager</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([filemgr <span style="color: #3d1d81;">fileExistsAtPath</span>: <span style="color: #4f8187;">databasePath</span> ] == <span style="color: #bb2ca2;">NO</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_open</span>([<span style="color: #4f8187;">databasePath</span> <span style="color: #3d1d81;">UTF8String</span>], &<span style="color: #4f8187;">db</span>) == <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *errMsg;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//use below code if you want ID in your table and update furhter code</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//const char *createQuery = "CREATE TABLE IF NOT EXISTS CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, ADDRESS TEXT, PHONE TEXT)";</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">const</span><span style="color: black;"> </span><span style="color: #bb2ca2;">char</span><span style="color: black;"> *createQuery = </span>"CREATE TABLE IF NOT EXISTS CONTACTS(NAME TEXT, ADDRESS TEXT, PHONE TEXT)"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_exec</span>(<span style="color: #4f8187;">db</span>, createQuery, <span style="color: #bb2ca2;">NULL</span>, <span style="color: #bb2ca2;">NULL</span>, &errMsg) != <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Failed to create table"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_close</span>(<span style="color: #4f8187;">db</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
} <span style="color: #bb2ca2;">else</span> {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Failed to open/create database"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Database already exists"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let me describe what we are doing in above method.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4.1 first of all we need to get the path of our device document directory</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;">dirPaths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
docsDirPath = [dirPaths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4.2 then we create our database path (database file name is : <span style="color: #d12f1b; font-family: Menlo; font-size: 11px;">contacts.db</span>)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithString<span style="color: black;">: [docsDirPath </span>stringByAppendingPathComponent<span style="color: black;">: </span><span style="color: #d12f1b;">@"contacts.db"</span><span style="color: black;">]];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4.3 and finally we created our database and Table using <span style="color: #703daa; font-family: Menlo; font-size: 11px;">NSFileManager</span> using create table query</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">const</span><span style="color: black;"> </span><span style="color: #bb2ca2;">char</span><span style="color: black;"> *createQuery = </span>"CREATE TABLE IF NOT EXISTS CONTACTS(NAME TEXT, ADDRESS TEXT, PHONE TEXT)"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #e32400;">Note</span>: <i>Here I have commented line for Creating Table with ID column,Coz I wanted to keep stuff simple.</i></div>
<div style="font-family: Menlo; font-size: 11px;">
<i>you can create Table with ID and different datatypes like Text, Integer etc.</i></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
5. Now create <b>insertContactInfoName</b> method to Insert values in Database</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName:(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> (</span>sqlite3_open<span style="color: black;">([</span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> </span>UTF8String<span style="color: black;">], &</span><span style="color: #4f8187;">db</span><span style="color: black;">) == </span><span style="color: #78492a;">SQLITE_OK</span><span style="color: black;">)</span></div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create insertStatement</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *insertStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create insertQuery</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">const</span><span style="color: black;"> </span><span style="color: #bb2ca2;">char</span><span style="color: black;"> *insertQuery = </span>"INSERT INTO CONTACTS (name,address,phone) VALUES (?,?,?)"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span>(<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span>, insertQuery, -<span style="color: #272ad8;">1</span>, &insertStatement, <span style="color: #bb2ca2;">NULL</span>) != <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #78492a;">NSAssert1</span><span style="color: black;">(</span><span style="color: #272ad8;">0</span><span style="color: black;">, </span>@"Error while creating add statement. '%s'"<span style="color: black;">, </span><span style="color: #3d1d81;">sqlite3_errmsg</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// insert values</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(insertStatement, <span style="color: #272ad8;">1</span>, [name <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(insertStatement, <span style="color: #272ad8;">2</span>, [address <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(insertStatement, <span style="color: #272ad8;">3</span>, [phoneNO <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_step</span>(insertStatement )== <span style="color: #78492a;">SQLITE_DONE</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Contact sucessfully saved : new item id is %lld"<span style="color: black;">,</span><span style="color: #3d1d81;">sqlite3_last_insert_rowid</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Failed to add contact"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_finalize</span>(insertStatement);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Here What we did is, Open the database,Created one statement, created SQL query then executed it by Prepare command and Got the result as newly created row's Id.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #e32400;"><i>Note</i></span><i>: don't forget to open the database before doing anything and close the database when you done!!</i></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #9929bd; font-family: Menlo; font-size: 11px;">
All below methods are doing SQL work in same way so keep in mind these things</div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="font-family: Monaco;">⁃</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Open the database<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="font-family: Monaco;">⁃</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Create Statement<span class="Apple-tab-span" style="white-space: pre;"> </span>|<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Menlo; font-size: 11px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="font-family: Monaco;">⁃</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Create SQL query<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="font-family: Monaco;">⁃</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Execute Query<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="font-family: Monaco;">⁃</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Get the result<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="font-family: Monaco;">⁃</span><span class="Apple-tab-span" style="white-space: pre;"> </span>Close the database<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
6. now write <span style="font-family: Menlo; font-size: 11px;"><b>selectAllContacts</b> </span>method body for select All contacts information</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> (</span>sqlite3_open<span style="color: black;">([</span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> </span>UTF8String<span style="color: black;">] , &</span><span style="color: #4f8187;">db</span><span style="color: black;">) == </span><span style="color: #78492a;">SQLITE_OK</span><span style="color: black;">){</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *selectStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *selectAllQuery = [<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"SELECT * FROM CONTACTS"</span>];</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"select All Query is = %@"<span style="color: black;">,selectAllQuery);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span> ,[selectAllQuery <span style="color: #3d1d81;">UTF8String</span>] , -<span style="color: #272ad8;">1</span>, &selectStatement, <span style="color: #bb2ca2;">NULL</span>) == <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">while</span> (<span style="color: #3d1d81;">sqlite3_step</span>(selectStatement) == <span style="color: #78492a;">SQLITE_ROW</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cName = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(selectStatement, <span style="color: #272ad8;">0</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cAddress = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(selectStatement, <span style="color: #272ad8;">1</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cPhone = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(selectStatement, <span style="color: #272ad8;">2</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cName];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cAddress];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cPhone];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@" Name = %@, Address = %@, PhoneNO = %@"<span style="color: black;">, name,address,phone);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_finalize</span>(selectStatement);</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">7. </span>now write <span style="font-family: Menlo; font-size: 11px;"><b>searchContactInfoByName</b> </span>method body for search contacts information by Name.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #4f8187;">ContactObject</span> *) searchContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">ContactObject</span> *aContactObject;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_open</span>([<span style="color: #4f8187;">databasePath</span> <span style="color: #3d1d81;">UTF8String</span>] , &<span style="color: #4f8187;">db</span>) == <span style="color: #78492a;">SQLITE_OK</span>){ </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *searchQuery = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithFormat</span><span style="color: black;">:</span>@"SELECT distinct name, address, phone FROM CONTACTS WHERE name = '%@'"<span style="color: black;">,name];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"search Query is : %@"<span style="color: black;">,searchQuery);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *searchStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span>, [searchQuery <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, &searchStatement, <span style="color: #bb2ca2;">nil</span>) == <span style="color: #78492a;">SQLITE_OK</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">while</span> (<span style="color: #3d1d81;">sqlite3_step</span>(searchStatement) == <span style="color: #78492a;">SQLITE_ROW</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cName = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(searchStatement, <span style="color: #272ad8;">0</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cAddress = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(searchStatement, <span style="color: #272ad8;">1</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cPhone = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(searchStatement, <span style="color: #272ad8;">2</span>); </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cName];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cAddress];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cPhone];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"We found Address = %@ Phone = %@"<span style="color: black;">,address,phone);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//put all results into object (our model)</div>
<div style="font-family: Menlo; font-size: 11px;">
aContactObject = [[<span style="color: #4f8187;">ContactObject</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #31595d;">initContactObjectByName</span>:name <span style="color: #31595d;">Address</span>:address <span style="color: #31595d;">PhoneNo</span>:phone]; </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_finalize</span>(searchStatement);</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@" The error is %s"<span style="color: black;">,</span><span style="color: #3d1d81;">sqlite3_errmsg</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> aContactObject;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
8. at last we you write <span style="font-family: Menlo; font-size: 11px;"><b>deleteContactInfoByName</b> </span>method body for search contacts information by Name.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_open</span>([<span style="color: #4f8187;">databasePath</span> <span style="color: #3d1d81;">UTF8String</span>], &<span style="color: #4f8187;">db</span> ) == <span style="color: #78492a;">SQLITE_OK</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *deleteStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *deleteQuery = [</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span><span style="color: #3d1d81;">stringWithFormat</span><span style="color: black;">:</span>@"DELETE FROM CONTACTS WHERE name = ?"<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Delete query is = %@"</span>,deleteQuery);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span> ,[deleteQuery <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, &deleteStatement, <span style="color: #bb2ca2;">NULL</span>) == <span style="color: #78492a;">SQLITE_OK</span>){</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//When binding parameters, index starts from 1 and not zero.</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(deleteStatement, <span style="color: #272ad8;">1</span>, [name <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #78492a;">SQLITE_DONE</span> == <span style="color: #3d1d81;">sqlite3_step</span>(deleteStatement)){</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"contact deleted successfully"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #78492a;">NSAssert1</span><span style="color: black;">(</span><span style="color: #272ad8;">0</span><span style="color: black;">, </span>@"Error while creating delete statement. '%s'"<span style="color: black;">, </span><span style="color: #3d1d81;">sqlite3_errmsg</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>DBHelper.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DBHelper.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"DBHelper.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ContactObject.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> DBHelper</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - DATABASE - INITILIZE</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #4f8187;">DBHelper</span> *dbHelper;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
+(<span style="color: #4f8187;">DBHelper</span> *)initializeDatabase{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">dbHelper</span> == <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//init method's body we will provide below</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">dbHelper</span> = [[<span style="color: #4f8187;">DBHelper</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>dbHelper<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">id</span>) init{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span> = [<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #bb2ca2;">self</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>createDatabase<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>self<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - SQLite DATABASE INFO</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
/*</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
*</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
* Database Name : contacts.db</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
* Database File Path : docsDirPath (log this string value)</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
* Database Table Name : CONTACTS</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
* Table Columns Name : NAME, ADDRESS, PHONE</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
*</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
*/</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - DATABASE - CREATE</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) createDatabase {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *dirPaths;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *docsDirPath;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Get the documents directory</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> dirPaths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
docsDirPath = [dirPaths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Build the path to the database file</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithString<span style="color: black;">: [docsDirPath </span>stringByAppendingPathComponent<span style="color: black;">: </span><span style="color: #d12f1b;">@"contacts.db"</span><span style="color: black;">]];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"database path is : %@"<span style="color: black;">,</span><span style="color: #4f8187;">databasePath</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//Now create the database</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSFileManager<span style="color: black;"> *filemgr = [</span>NSFileManager<span style="color: black;"> </span><span style="color: #3d1d81;">defaultManager</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([filemgr <span style="color: #3d1d81;">fileExistsAtPath</span>: <span style="color: #4f8187;">databasePath</span> ] == <span style="color: #bb2ca2;">NO</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_open</span>([<span style="color: #4f8187;">databasePath</span> <span style="color: #3d1d81;">UTF8String</span>], &<span style="color: #4f8187;">db</span>) == <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *errMsg;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//use below code if you want ID in your table and update furhter code</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//const char *createQuery = "CREATE TABLE IF NOT EXISTS CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, ADDRESS TEXT, PHONE TEXT)";</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">const</span><span style="color: black;"> </span><span style="color: #bb2ca2;">char</span><span style="color: black;"> *createQuery = </span>"CREATE TABLE IF NOT EXISTS CONTACTS(NAME TEXT, ADDRESS TEXT, PHONE TEXT)"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_exec</span>(<span style="color: #4f8187;">db</span>, createQuery, <span style="color: #bb2ca2;">NULL</span>, <span style="color: #bb2ca2;">NULL</span>, &errMsg) != <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Failed to create table"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_close</span>(<span style="color: #4f8187;">db</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
} <span style="color: #bb2ca2;">else</span> {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Failed to open/create database"<span style="color: black;">); </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Database already exists"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - DATABASE -INSERT</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) insertContactInfoName:(<span style="color: #703daa;">NSString</span> *)name Address:(<span style="color: #703daa;">NSString</span> *)address PhoneNo:(<span style="color: #703daa;">NSString</span> *)phoneNO{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> (</span>sqlite3_open<span style="color: black;">([</span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> </span>UTF8String<span style="color: black;">], &</span><span style="color: #4f8187;">db</span><span style="color: black;">) == </span><span style="color: #78492a;">SQLITE_OK</span><span style="color: black;">)</span></div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create insertStatement</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *insertStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create insertQuery</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">const</span><span style="color: black;"> </span><span style="color: #bb2ca2;">char</span><span style="color: black;"> *insertQuery = </span>"INSERT INTO CONTACTS (name,address,phone) VALUES (?,?,?)"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span>(<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span>, insertQuery, -<span style="color: #272ad8;">1</span>, &insertStatement, <span style="color: #bb2ca2;">NULL</span>) != <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #78492a;">NSAssert1</span><span style="color: black;">(</span><span style="color: #272ad8;">0</span><span style="color: black;">, </span>@"Error while creating add statement. '%s'"<span style="color: black;">, </span><span style="color: #3d1d81;">sqlite3_errmsg</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// insert values</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(insertStatement, <span style="color: #272ad8;">1</span>, [name <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(insertStatement, <span style="color: #272ad8;">2</span>, [address <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(insertStatement, <span style="color: #272ad8;">3</span>, [phoneNO <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_step</span>(insertStatement )== <span style="color: #78492a;">SQLITE_DONE</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Contact sucessfully saved : new item id is %lld"<span style="color: black;">,</span><span style="color: #3d1d81;">sqlite3_last_insert_rowid</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{ </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Failed to add contact"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_finalize</span>(insertStatement); </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - DATABASE -SELECT ALL DATA</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) selectAllContacts{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> (</span>sqlite3_open<span style="color: black;">([</span><span style="color: #4f8187;">databasePath</span><span style="color: black;"> </span>UTF8String<span style="color: black;">] , &</span><span style="color: #4f8187;">db</span><span style="color: black;">) == </span><span style="color: #78492a;">SQLITE_OK</span><span style="color: black;">){</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *selectStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *selectAllQuery = [<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"SELECT * FROM CONTACTS"</span>];</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"select All Query is = %@"<span style="color: black;">,selectAllQuery);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span> ,[selectAllQuery <span style="color: #3d1d81;">UTF8String</span>] , -<span style="color: #272ad8;">1</span>, &selectStatement, <span style="color: #bb2ca2;">NULL</span>) == <span style="color: #78492a;">SQLITE_OK</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">while</span> (<span style="color: #3d1d81;">sqlite3_step</span>(selectStatement) == <span style="color: #78492a;">SQLITE_ROW</span>)</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cName = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(selectStatement, <span style="color: #272ad8;">0</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cAddress = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(selectStatement, <span style="color: #272ad8;">1</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cPhone = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(selectStatement, <span style="color: #272ad8;">2</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cName];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cAddress];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cPhone];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@" Name = %@, Address = %@, PhoneNO = %@"<span style="color: black;">, name,address,phone);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_finalize</span>(selectStatement);</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - DATABASE - SEARCH</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//this method will returns an Object which contains one person's Contact info details</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #4f8187;">ContactObject</span> *) searchContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">ContactObject</span> *aContactObject;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_open</span>([<span style="color: #4f8187;">databasePath</span> <span style="color: #3d1d81;">UTF8String</span>] , &<span style="color: #4f8187;">db</span>) == <span style="color: #78492a;">SQLITE_OK</span>){ </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *searchQuery = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithFormat</span><span style="color: black;">:</span>@"SELECT distinct name, address, phone FROM CONTACTS WHERE name = '%@'"<span style="color: black;">,name];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"search Query is : %@"<span style="color: black;">,searchQuery);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *searchStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span>, [searchQuery <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, &searchStatement, <span style="color: #bb2ca2;">nil</span>) == <span style="color: #78492a;">SQLITE_OK</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">while</span> (<span style="color: #3d1d81;">sqlite3_step</span>(searchStatement) == <span style="color: #78492a;">SQLITE_ROW</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cName = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(searchStatement, <span style="color: #272ad8;">0</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cAddress = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(searchStatement, <span style="color: #272ad8;">1</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *cPhone = (<span style="color: #bb2ca2;">char</span> *) <span style="color: #3d1d81;">sqlite3_column_text</span>(searchStatement, <span style="color: #272ad8;">2</span>); </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cName];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cAddress];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithUTF8String</span>:cPhone];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"We found Address = %@ Phone = %@"<span style="color: black;">,address,phone);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//put all results into object (our model)</div>
<div style="font-family: Menlo; font-size: 11px;">
aContactObject = [[<span style="color: #4f8187;">ContactObject</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #31595d;">initContactObjectByName</span>:name <span style="color: #31595d;">Address</span>:address <span style="color: #31595d;">PhoneNo</span>:phone]; </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_finalize</span>(searchStatement);</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@" The error is %s"<span style="color: black;">,</span><span style="color: #3d1d81;">sqlite3_errmsg</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>sqlite3_close<span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> aContactObject; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - DATABASE - DELETE</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) deleteContactInfoByName:(<span style="color: #703daa;">NSString</span> *)name{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_open</span>([<span style="color: #4f8187;">databasePath</span> <span style="color: #3d1d81;">UTF8String</span>], &<span style="color: #4f8187;">db</span> ) == <span style="color: #78492a;">SQLITE_OK</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">sqlite3_stmt</span> *deleteStatement;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *deleteQuery = [</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span><span style="color: #3d1d81;">stringWithFormat</span><span style="color: black;">:</span>@"DELETE FROM CONTACTS WHERE name = ?"<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Delete query is = %@"</span>,deleteQuery);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #3d1d81;">sqlite3_prepare_v2</span>(<span style="color: #4f8187;">db</span> ,[deleteQuery <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, &deleteStatement, <span style="color: #bb2ca2;">NULL</span>) == <span style="color: #78492a;">SQLITE_OK</span>){</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//When binding parameters, index starts from 1 and not zero.</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">sqlite3_bind_text</span>(deleteStatement, <span style="color: #272ad8;">1</span>, [name <span style="color: #3d1d81;">UTF8String</span>], -<span style="color: #272ad8;">1</span>, <span style="color: #78492a;">SQLITE_TRANSIENT</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #78492a;">SQLITE_DONE</span> == <span style="color: #3d1d81;">sqlite3_step</span>(deleteStatement)){</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"contact deleted successfully"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #78492a;">NSAssert1</span><span style="color: black;">(</span><span style="color: #272ad8;">0</span><span style="color: black;">, </span>@"Error while creating delete statement. '%s'"<span style="color: black;">, </span><span style="color: #3d1d81;">sqlite3_errmsg</span><span style="color: black;">(</span><span style="color: #4f8187;">db</span><span style="color: black;">));</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are about to Accomplish our goal, So, stay tune with RDC.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
This time we use all the hard-work we have done in Model or Helper classes.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">Open </span>ViewController.h<span style="color: black; font-family: Helvetica; font-size: 12px;"> file</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. we need to use Model class instance hence add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class </span>for that</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ContactObject<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. add protocol <span style="color: #703daa;">UITextFieldDelegate </span>because we will enable Keypad Go back when user hit Return Key on any TextFiled</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UITextFieldDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. You can see some IBOutlets and IBActions methods we already Added By Xcode, we did it From UI.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. declare property for our Model class instance</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #4f8187;">ContactObject</span><span style="color: black;"> *aContactObject;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
4. declare property of TextField class instance, we will use this, for which TextFiled is active for sending keypad back.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *active_text;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Good! save this File.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ContactObject<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UITextFieldDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *nameTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *addressTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *phoneNoTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #4f8187;">ContactObject</span><span style="color: black;"> *aContactObject;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *active_text;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#import </span>statement for Model class and DBHelper, we are going to use them in this </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"DBHelper.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ContactObject.h"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> addressTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> phoneNoTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> aContactObject;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> active_text;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>saveContactInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">phoneNoTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> && [address <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span> && [phone <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>insertContactInfoName<span style="color: black;">:name </span>Address<span style="color: black;">:address </span>PhoneNo<span style="color: black;">:phone];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>viewAllContactsInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//for all the results we printed on console in DBHelper's file method itself</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>selectAllContacts<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>searchContactInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">aContactObject</span><span style="color: black;"> =[[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>searchContactInfoByName<span style="color: black;">:name];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">aContactObject</span>.<span style="color: #4f8187;">name</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">aContactObject</span>.<span style="color: #4f8187;">address</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">aContactObject</span>.<span style="color: #4f8187;">phoneNO</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@"Search Result"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"We found Name : %@, Address : %@, Phone No : %@"</span>,name,address,phone]</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"OK"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">phoneNoTextField</span>.<span style="color: #703daa;">text</span>=<span style="color: #d12f1b;">@""</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">5. </span>update the body of <span style="font-family: Menlo; font-size: 11px;"><b>deleteContactInfo</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span> <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> ) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>deleteContactInfoByName<span style="color: black;">:</span><span style="color: #4f8187;">nameTextField</span><span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span> <span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"OK"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
6. now we will implement UITextFiled's Delegate method to handle Keypad Go Back when user Hit Return key</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>)textFieldDidBeginEditing:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">active_text</span> = textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>TRUE<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"DBHelper.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ContactObject.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> addressTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> phoneNoTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> aContactObject;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> active_text;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's LifeCycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//optional : if you having problem with TextField's Delegate Hookup in UI</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//nameTextField.delegate =self;</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//addressTextField.delegate=self;</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//phoneNoTextField.delegate=self;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Buttons click methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveContactInfo:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">phoneNoTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> && [address <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span> && [phone <span style="color: #3d1d81;">length</span>]><span style="color: #272ad8;">1</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>insertContactInfoName<span style="color: black;">:name </span>Address<span style="color: black;">:address </span>PhoneNo<span style="color: black;">:phone];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span> <span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)viewAllContactsInfo:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//for all the results we printed on console in DBHelper's file method itself</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>selectAllContacts<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)searchContactInfo:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">aContactObject</span><span style="color: black;"> =[[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>searchContactInfoByName<span style="color: black;">:name];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">aContactObject</span>.<span style="color: #4f8187;">name</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">aContactObject</span>.<span style="color: #4f8187;">address</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">aContactObject</span>.<span style="color: #4f8187;">phoneNO</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@"Search Result"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"We found Name : %@, Address : %@, Phone No : %@"</span>,name,address,phone]</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"OK"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">phoneNoTextField</span>.<span style="color: #703daa;">text</span>=<span style="color: #d12f1b;">@""</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span> <span style="color: #3d1d81;">delegate</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">cancelButtonTitle</span>:<span style="color: #d12f1b;">@"OK"</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">otherButtonTitles</span>:<span style="color: #bb2ca2;">nil</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)deleteContactInfo:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> ([<span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span> <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> ) {</div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [[</span><span style="color: #4f8187;">DBHelper</span><span style="color: black;"> </span>initializeDatabase<span style="color: black;">] </span>deleteContactInfoByName<span style="color: black;">:</span><span style="color: #4f8187;">nameTextField</span><span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>nameTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> =</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>addressTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>phoneNoTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIAlertView</span> *alert = [[<span style="color: #703daa;">UIAlertView</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTitle</span>:<span style="color: #d12f1b;">@""</span> <span style="color: #3d1d81;">message</span>:<span style="color: #d12f1b;">@"please! enter text"</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"OK"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UITextField Delegate methods for Keypad Return key</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>)textFieldDidBeginEditing:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">active_text</span> = textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">BOOL</span>)textFieldShouldReturn:(<span style="color: #703daa;">UITextField</span> *)textField{ </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [textField </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>TRUE<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SQLiteDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/7/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB-Jl64ojKKrpBTnrh7pgdFikN1-Nv6Qp_BIQ-K9Xu4aLvni5mSvcVvDI-aQtCH1__I32I3x4xnae5SGNIu9sWwmBrsSK-wFFFyEVdNjmxfZ_CFts15bUvOzlEKxzi4f3JWh4iGKZscolV/s1600/Screen+17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB-Jl64ojKKrpBTnrh7pgdFikN1-Nv6Qp_BIQ-K9Xu4aLvni5mSvcVvDI-aQtCH1__I32I3x4xnae5SGNIu9sWwmBrsSK-wFFFyEVdNjmxfZ_CFts15bUvOzlEKxzi4f3JWh4iGKZscolV/s320/Screen+17.png" width="213" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can Find the ViewAll results in Console</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_nL0x2KKlnu_SSgrnoAt4JE0MhvniK2yEwAZt1hxKXWlYFzi9ROz5VWOdmvAmZd3N54BHLow7d6o-_djTbaQe-PU56ZXLDmKXWNZteV9YSr-0A11I3bBkjw2RZUJ6l-4w0fc79kQ6ngL3/s1600/Screen18.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="46" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_nL0x2KKlnu_SSgrnoAt4JE0MhvniK2yEwAZt1hxKXWlYFzi9ROz5VWOdmvAmZd3N54BHLow7d6o-_djTbaQe-PU56ZXLDmKXWNZteV9YSr-0A11I3bBkjw2RZUJ6l-4w0fc79kQ6ngL3/s320/Screen18.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica;">
<span style="font-size: 12px;">You can find complete project source code zip file here : </span><span style="background-color: #d5e2ed; font-family: arial; line-height: 32px; text-align: center;"><span style="color: #38761d; font-size: x-small;"><a href="https://www.opendrive.com/files?M182MDY5MDg4X2RadUd5" target="_blank"><b>SQLiteDemo.zip (81.24 KB)</b></a></span></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com2Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-5455036060928905242013-03-06T03:15:00.000-08:002013-03-06T03:32:54.126-08:00UICollection View in iOS 6 Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Today we are going to learn of the new feature added by Apple guys in iOS 6.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYZUMznnGnsYtfi5x-682sMd1_9BiD9u10AZmG72k9Ufh3njbGCAV1xKxbxPDgwLAE1B2yCbn1cHkl-nma6HrEQU6EivXtiIEUXtxihvcA8oQ9awiynQkbm-aIFiymxP3pgtbJ3fIMz-37/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYZUMznnGnsYtfi5x-682sMd1_9BiD9u10AZmG72k9Ufh3njbGCAV1xKxbxPDgwLAE1B2yCbn1cHkl-nma6HrEQU6EivXtiIEUXtxihvcA8oQ9awiynQkbm-aIFiymxP3pgtbJ3fIMz-37/s320/Screen+0.png" width="163" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #ff4013; font-family: Helvetica; font-size: 12px;">
Note : This Application Developed Using : iOS 6</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Product Name : <b>CollectionViewDemo</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Organization Name :<b>RDCWorld</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Company Identifier : <b>com.rdcworld</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave it blank for now)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Devices : <b>iPhone</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
Note : <i>Don't forget to Make Tick mark on "Use Automatic Reference Counting" option</i>.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCf3lQIYNL-l5slhZ-wsrMombQVLSRcEQcFtxCbV3IOKMEMGNVUDmRx02SEYDHsXH-xGh35ubyIjS12dKAQJmFWdpSjssojzswKebFsBQN67YOtX-37AITQMCZDHjJXrkziv6yX2qzTNmb/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCf3lQIYNL-l5slhZ-wsrMombQVLSRcEQcFtxCbV3IOKMEMGNVUDmRx02SEYDHsXH-xGh35ubyIjS12dKAQJmFWdpSjssojzswKebFsBQN67YOtX-37AITQMCZDHjJXrkziv6yX2qzTNmb/s320/Screen+2.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add UICollectionView and UICollectionViewCell on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
UICollectionView : for showing our data (image, text etc) in a grid form</div>
<div style="font-family: Helvetica; font-size: 12px;">
UICollectionViewCell : for design particular cell on Collection view</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px;">
1. let's drag UICollectionView from Object library and fill it on layout as shown in picture</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNNd6EPXVkGQ3dYDx-1QwYlvXh4Xf7hF_wa0PURZVrtcAw4Sm-mdXM4qVU61U_jaD-6GbogHT84gFs60zcGXTQwTRfGjFJPD7PNaIMDtJiJnTWXZhRQ99YJYIrcPfKtRqsI30iAoz1eBNb/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNNd6EPXVkGQ3dYDx-1QwYlvXh4Xf7hF_wa0PURZVrtcAw4Sm-mdXM4qVU61U_jaD-6GbogHT84gFs60zcGXTQwTRfGjFJPD7PNaIMDtJiJnTWXZhRQ99YJYIrcPfKtRqsI30iAoz1eBNb/s320/Screen+3.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. now we need to create a Layout for our CollectionView cell, so we are going to add one XIB file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
File Menu --> New --> File</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select <b>View</b> templet in "User Interface" option under iOS (see popup window screen shot), go next</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS_XDY8eHtBxUGMkafNpR8Q0xK1Bv99oNGOOfy5a3oMledxyjH6515KngioOslG-NyPcHrdpzmgWebO7BNTYgIypfXjq0MVWIYAGjg_4_DvQ-A4WONHVpUPCK-38CJyhtFCFuXMrGTghrp/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS_XDY8eHtBxUGMkafNpR8Q0xK1Bv99oNGOOfy5a3oMledxyjH6515KngioOslG-NyPcHrdpzmgWebO7BNTYgIypfXjq0MVWIYAGjg_4_DvQ-A4WONHVpUPCK-38CJyhtFCFuXMrGTghrp/s320/Screen+4.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
select device family : we are creating for iPhone.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidrNIxtVKwVbz0H-nEWb0oPI3Q3xvbLzNOG7h5USNOU74SgQDMLi84lNIPFpqtoD-e0KdV1KwCH1kp9el_MJ7xPqSo4NXLDUWz3fZ8GlV5ddblbEfNN_ab6uwN08-ELhC67GJSKh-zcIKd/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidrNIxtVKwVbz0H-nEWb0oPI3Q3xvbLzNOG7h5USNOU74SgQDMLi84lNIPFpqtoD-e0KdV1KwCH1kp9el_MJ7xPqSo4NXLDUWz3fZ8GlV5ddblbEfNN_ab6uwN08-ELhC67GJSKh-zcIKd/s1600/Screen+5.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Given it name as "MyCell" and go for create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjptb0Y6IuJQY9S1bMk3mp8H_Pkw5FTPPogLS-F_5y455sGohhwtJ3z_ffG78e-HsyuR5tK2TE6nEFHCBm5TWTG2OGlcHlR0uNcrOp5QMTcDtRVsEig8pTbBbrgD6pOXzYv5wyozgI80cbO/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="221" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjptb0Y6IuJQY9S1bMk3mp8H_Pkw5FTPPogLS-F_5y455sGohhwtJ3z_ffG78e-HsyuR5tK2TE6nEFHCBm5TWTG2OGlcHlR0uNcrOp5QMTcDtRVsEig8pTbBbrgD6pOXzYv5wyozgI80cbO/s320/Screen+6.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Good!! now you can see default blank layout, just delete it (select it and press delete button) and drag UICollectionViewCell from object library</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs0P0yJi_ipFPgpaJ50S_Pw-Lt4Z25a7MuJpy11P0IP9xpS9uNXsePNi1oZOAZfdrfWaPk-puYi-XxsQhwF4hyphenhyphennkXOUSGwEh9IdHNRZPT3Qkz_MV3b2hCHTL6QRPuI-Q272Qh2HqG2LbQo/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs0P0yJi_ipFPgpaJ50S_Pw-Lt4Z25a7MuJpy11P0IP9xpS9uNXsePNi1oZOAZfdrfWaPk-puYi-XxsQhwF4hyphenhyphennkXOUSGwEh9IdHNRZPT3Qkz_MV3b2hCHTL6QRPuI-Q272Qh2HqG2LbQo/s1600/Screen+7.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now go the <b>Size Inspector</b> and change width=100 and hight =100</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif2tOvVFzcbc760o4rjV0arJ3h5mHXYbWsCLSpHW8WlbmJDPRkceHf8GB2pg0HYi2PFiV3WHL6Uii4BlRI7Qd7XwxZXKrYIKouzdSRDKtqmDo3-OycjrG7IYDb4Dpmq1g6KLEzeV4H5G0x/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif2tOvVFzcbc760o4rjV0arJ3h5mHXYbWsCLSpHW8WlbmJDPRkceHf8GB2pg0HYi2PFiV3WHL6Uii4BlRI7Qd7XwxZXKrYIKouzdSRDKtqmDo3-OycjrG7IYDb4Dpmq1g6KLEzeV4H5G0x/s1600/Screen+8.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now select Attribute Inspector and change Background color and then drag UILabel on it as below image</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJxUrmK4Qsv1aO6_j018V54tkKblV967Wpc46-6bBz2VIvjk0rk8ARvmfq110dn9CoBnp4VNE6lVi0b7b9e_cwFOdqowf1nSEqhQYK2aYaEvj6NFRGArqGERAybLIdB36Cy0hyphenhyphen6HRpbgs2/s1600/Screen+9+.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJxUrmK4Qsv1aO6_j018V54tkKblV967Wpc46-6bBz2VIvjk0rk8ARvmfq110dn9CoBnp4VNE6lVi0b7b9e_cwFOdqowf1nSEqhQYK2aYaEvj6NFRGArqGERAybLIdB36Cy0hyphenhyphen6HRpbgs2/s1600/Screen+9+.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
select UILabel --> in Attribute Inspector --> scroll down and change its Tag = 100 (because we need to get it in ViewController.m file)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time our project structure is look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwN5tSn-BsyRThn-v8-HfzutGHtoGYDpdaHgj7yom2Veite1lLF5x3y3ou70l1LbABGuFIU_-E76kt5Du-9hyzXFNQ8xUfwGKTrFhvzBmH5MPcMaDhRxoZLuevSomDeDHcu1p-QVdefYkV/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwN5tSn-BsyRThn-v8-HfzutGHtoGYDpdaHgj7yom2Veite1lLF5x3y3ou70l1LbABGuFIU_-E76kt5Du-9hyzXFNQ8xUfwGKTrFhvzBmH5MPcMaDhRxoZLuevSomDeDHcu1p-QVdefYkV/s320/Screen+10.png" width="200" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UICollectionView .</div>
<div style="font-family: Helvetica; font-size: 12px;">
So just open ViewController.xib</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select UICollectionView --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGty4x8XqI3YOdtoU-JBQTac-g7hPYR9EXnPeb05rO-KuWh4U8DaXX2-8M_hvuiLASpnPrc74WeRXfaSBoDf0jBruKF65gEZdsslNxJOnQ9EYdrN7gJgBVLDMJ7apXSAD83JH0muXylCnM/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="151" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGty4x8XqI3YOdtoU-JBQTac-g7hPYR9EXnPeb05rO-KuWh4U8DaXX2-8M_hvuiLASpnPrc74WeRXfaSBoDf0jBruKF65gEZdsslNxJOnQ9EYdrN7gJgBVLDMJ7apXSAD83JH0muXylCnM/s320/Screen+12.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">myCollectionView</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjz39hbUjGc54cBHbdKLhCS28TAspQCPeOekJfQnD2lYXfLWRwD1LmKzhi2kVufezUWNJmM25Umf_l9HjoJnh8XSQiiYzoy7bgjuWqGc5TvqySDya6FCyU_sL06jrr_4TCorQ7JAk2y72MG/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjz39hbUjGc54cBHbdKLhCS28TAspQCPeOekJfQnD2lYXfLWRwD1LmKzhi2kVufezUWNJmM25Umf_l9HjoJnh8XSQiiYzoy7bgjuWqGc5TvqySDya6FCyU_sL06jrr_4TCorQ7JAk2y72MG/s1600/Screen+13.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Hook Up Delegate and Datasource)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to mentioned that we are going to implement UICollectionView's Datasource and Delegate protocols,</div>
<div style="font-family: Helvetica; font-size: 12px;">
so do it now, later we will define in our ViewController.h file too.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. sélect ViewController.xib file.</div>
<div style="font-family: Helvetica; font-size: 12px;">
2. select UICollection</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
On top right corner (below to Organizer tab) select <b>Connection Inspector</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Click on DataSource and drag it to the File owner as shown in below screen shot</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw7HHaI7GDrtUPZhW3p0dn4ZwUzFJNRmX8955BuQahk2dDw7apcBIt56nAehfpSCRHPyrw8qoly3zeyYXc1qch8fFA4ct6KOMVur_k-0sYsXBE_qhp0jS3MKXGHVnz5JympJwwrfdduT-7/s1600/screen+15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="172" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw7HHaI7GDrtUPZhW3p0dn4ZwUzFJNRmX8955BuQahk2dDw7apcBIt56nAehfpSCRHPyrw8qoly3zeyYXc1qch8fFA4ct6KOMVur_k-0sYsXBE_qhp0jS3MKXGHVnz5JympJwwrfdduT-7/s320/screen+15.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now do the same for Delegate (Drag delegate to the file owner)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<i>Note : you can achieve same by adding below two lines in viewDidLoad method of your ViewController.m file </i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
myCollectionView<span style="color: black;">.</span><span style="color: #703daa;">dataSource</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
myCollectionView<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;">=</span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! You are on the way!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Save app, and open ViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">1. add UICollectionView's protocols </span><span style="color: black;"><</span>UICollectionViewDataSource<span style="color: black;">, </span>UICollectionViewDelegate<span style="color: black;">> to </span><span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UICollectionViewDataSource<span style="color: black;">, </span>UICollectionViewDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. define mutable array with property, name as "contentArray"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSMutableArray</span><span style="color: black;"> *contentArray;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.h file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CollectionViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/6/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UICollectionViewDataSource<span style="color: black;">, </span>UICollectionViewDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UICollectionView</span><span style="color: black;"> *myCollectionView;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSMutableArray</span><span style="color: black;"> *contentArray;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myCollectionView;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> contentArray;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. in viewDidLoad method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 Initialize our content array and put the data into it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">contentArray</span> = [[<span style="color: #703daa;">NSMutableArray</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span> (<span style="color: #bb2ca2;">int</span> i=<span style="color: #272ad8;">0</span>; i<<span style="color: #272ad8;">100</span>; i++) {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">contentArray</span><span style="color: black;"> </span>addObject<span style="color: black;">:[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>stringWithFormat<span style="color: black;">:</span><span style="color: #d12f1b;">@"Cell %d"</span><span style="color: black;">,i]];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 get the UICollectionViewCell's Nib file (.xib file) here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;"><span class="Apple-tab-span" style="white-space: pre;"> </span>UINib</span><span style="color: black;"> *cellNib = [</span><span style="color: #703daa;">UINib</span><span style="color: black;"> </span>nibWithNibName<span style="color: black;">:</span><span style="color: #d12f1b;">@"MyCell"</span><span style="color: black;"> </span>bundle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myCollectionView</span><span style="color: black;"> </span>registerNib<span style="color: black;">:cellNib </span>forCellWithReuseIdentifier<span style="color: black;">:</span><span style="color: #d12f1b;">@"cvCell"</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.3 create FlowLayout for collection view with its item size</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UICollectionViewFlowLayout<span style="color: black;"> *flowLayout = [[</span>UICollectionViewFlowLayout<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[flowLayout <span style="color: #3d1d81;">setItemSize</span>:<span style="color: #3d1d81;">CGSizeMake</span>(<span style="color: #272ad8;">100</span>, <span style="color: #272ad8;">100</span>)];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.4 add scroll direction (in this we want as Horizontal scroll)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;">[flowLayout </span>setScrollDirection<span style="color: black;">:</span>UICollectionViewScrollDirectionHorizontal<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.5 add FlowLayout to our Main collectionView</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;">[</span><span style="color: #4f8187;">myCollectionView</span><span style="color: black;"> </span>setCollectionViewLayout<span style="color: black;">:flowLayout];</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Now Heart of the Application : we need to implement UICollectionView's Datasource & Delegate method</div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : we have already declared these protocols in header file and Hooked up with Layout.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here we have some optional and mandatory methods, I will mention</div>
<div style="font-family: Helvetica; font-size: 12px;">
at the end of file but before <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@end </span>add these methods</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DataSource - optional method</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSInteger</span>)numberOfSectionsInCollectionView: (<span style="color: #703daa;">UICollectionView</span> *)collectionView {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> <span style="color: #272ad8;">1</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DataSource - mandatory methods</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSInteger</span>) collectionView:(<span style="color: #703daa;">UICollectionView</span> *)collectionView numberOfItemsInSection:(<span style="color: #703daa;">NSInteger</span>)section{</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> [</span>contentArray<span style="color: black;"> </span><span style="color: #3d1d81;">count</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">UICollectionViewCell</span> *)collectionView:(<span style="color: #703daa;">UICollectionView</span> *)collectionView cellForItemAtIndexPath:(<span style="color: #703daa;">NSIndexPath</span> *)indexPath { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *cellData = [<span style="color: #4f8187;">contentArray</span> <span style="color: #3d1d81;">objectAtIndex</span>:indexPath.<span style="color: #703daa;">row</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #703daa;">NSString</span> *cellIdentifier = <span style="color: #d12f1b;">@"cvCell"</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UICollectionViewCell</span> *cell = [collectionView <span style="color: #3d1d81;">dequeueReusableCellWithReuseIdentifier</span>:cellIdentifier <span style="color: #3d1d81;">forIndexPath</span>:indexPath]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UILabel</span> *titleLabel = (<span style="color: #703daa;">UILabel</span> *)[cell <span style="color: #3d1d81;">viewWithTag</span>:<span style="color: #272ad8;">100</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
[titleLabel <span style="color: #3d1d81;">setText</span>:cellData]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> cell; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Delegate - optional method</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) collectionView:(<span style="color: #703daa;">UICollectionView</span> *)collectionView didSelectItemAtIndexPath:(<span style="color: #703daa;">NSIndexPath</span> *)indexPath{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *cellData = [<span style="color: #4f8187;">contentArray</span> <span style="color: #3d1d81;">objectAtIndex</span>:indexPath.<span style="color: #703daa;">row</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>stringWithFormat<span style="color: black;">:</span><span style="color: #d12f1b;">@"You have selected %@ item"</span><span style="color: black;">,cellData] </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.m file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CollectionViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/6/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myCollectionView;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> contentArray;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's Life Cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//initialize array and put data on it</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">contentArray</span> = [[<span style="color: #703daa;">NSMutableArray</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">init</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span> (<span style="color: #bb2ca2;">int</span> i=<span style="color: #272ad8;">0</span>; i<<span style="color: #272ad8;">100</span>; i++) {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">contentArray</span><span style="color: black;"> </span>addObject<span style="color: black;">:[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>stringWithFormat<span style="color: black;">:</span><span style="color: #d12f1b;">@"Cell %d"</span><span style="color: black;">,i]];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the cell nib we have created</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UINib</span> *cellNib = [<span style="color: #703daa;">UINib</span> <span style="color: #3d1d81;">nibWithNibName</span>:<span style="color: #d12f1b;">@"MyCell"</span> <span style="color: #3d1d81;">bundle</span>:<span style="color: #bb2ca2;">nil</span>];</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myCollectionView</span><span style="color: black;"> </span>registerNib<span style="color: black;">:cellNib </span>forCellWithReuseIdentifier<span style="color: black;">:</span><span style="color: #d12f1b;">@"cvCell"</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create flow layout</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UICollectionViewFlowLayout<span style="color: black;"> *flowLayout = [[</span>UICollectionViewFlowLayout<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[flowLayout <span style="color: #3d1d81;">setItemSize</span>:<span style="color: #3d1d81;">CGSizeMake</span>(<span style="color: #272ad8;">100</span>, <span style="color: #272ad8;">100</span>)];</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [flowLayout </span>setScrollDirection<span style="color: black;">:</span>UICollectionViewScrollDirectionHorizontal<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add flow layout to our collection view</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myCollectionView</span><span style="color: black;"> </span>setCollectionViewLayout<span style="color: black;">:flowLayout];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//optional : if you didn't hook up Datasource and delegate with File owner, you can use this</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//myCollectionView.dataSource = self;</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//myCollectionView.delegate=self;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UICollectionView DataSource methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DataSource - optional method</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSInteger</span>)numberOfSectionsInCollectionView: (<span style="color: #703daa;">UICollectionView</span> *)collectionView {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> <span style="color: #272ad8;">1</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DataSource - mandatory methods</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSInteger</span>) collectionView:(<span style="color: #703daa;">UICollectionView</span> *)collectionView numberOfItemsInSection:(<span style="color: #703daa;">NSInteger</span>)section{</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> [</span>contentArray<span style="color: black;"> </span><span style="color: #3d1d81;">count</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">UICollectionViewCell</span> *)collectionView:(<span style="color: #703daa;">UICollectionView</span> *)collectionView cellForItemAtIndexPath:(<span style="color: #703daa;">NSIndexPath</span> *)indexPath {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *cellData = [<span style="color: #4f8187;">contentArray</span> <span style="color: #3d1d81;">objectAtIndex</span>:indexPath.<span style="color: #703daa;">row</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #703daa;">NSString</span> *cellIdentifier = <span style="color: #d12f1b;">@"cvCell"</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UICollectionViewCell</span> *cell = [collectionView <span style="color: #3d1d81;">dequeueReusableCellWithReuseIdentifier</span>:cellIdentifier <span style="color: #3d1d81;">forIndexPath</span>:indexPath]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UILabel</span> *titleLabel = (<span style="color: #703daa;">UILabel</span> *)[cell <span style="color: #3d1d81;">viewWithTag</span>:<span style="color: #272ad8;">100</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
[titleLabel <span style="color: #3d1d81;">setText</span>:cellData]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> cell; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UICollectionView Delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Delegate - optional method</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) collectionView:(<span style="color: #703daa;">UICollectionView</span> *)collectionView didSelectItemAtIndexPath:(<span style="color: #703daa;">NSIndexPath</span> *)indexPath{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *cellData = [<span style="color: #4f8187;">contentArray</span> <span style="color: #3d1d81;">objectAtIndex</span>:indexPath.<span style="color: #703daa;">row</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>stringWithFormat<span style="color: black;">:</span><span style="color: #d12f1b;">@"You have selected %@ item"</span><span style="color: black;">,cellData] </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CollectionViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/6/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CollectionViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/6/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJp61U4u4qXQtgwO6Q6bA9QxDTzcBFNydzunOm4qQfAhiQJnZtA2lXIqgL9aRP8mSNwgQAq_MQiy2Bl5lHDi5DTvJcxtzprgWby7vYEUyU-yyfGx9MXj5adzWvqrQZHpp-0tjVsnhm1Yzs/s1600/Screen+16.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJp61U4u4qXQtgwO6Q6bA9QxDTzcBFNydzunOm4qQfAhiQJnZtA2lXIqgL9aRP8mSNwgQAq_MQiy2Bl5lHDi5DTvJcxtzprgWby7vYEUyU-yyfGx9MXj5adzWvqrQZHpp-0tjVsnhm1Yzs/s320/Screen+16.png" width="213" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. It was so simple because <span style="color: #008400; font-family: Menlo; font-size: 11px;">Apple </span>did everything for us.</div>
<div style="font-family: Helvetica; font-size: 12px;">
we just made it alive.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <span style="text-align: center;"><a href="https://www.opendrive.com/files?M181OTYxMTUyX25ieXpJ" target="_blank"><b><span style="color: #38761d;">CollectionViewDemo.zip (73.94 KB)</span></b></a></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
<div>
<br /></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-69161115206526548942013-03-05T23:14:00.000-08:002013-03-05T23:19:15.465-08:00CollectionView in iOS 6 (Complete Theory)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
The Collection View have been introduced as part of iOS 6. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqCOlOk8F-Uj2r-A9SjCn0Ca3AFE0ccEg07-ELUDbqHrXfcePJmirDXRPyVOlkD3tJ1bl1uhvKSe4ew15r7LnsB3-9d8JUDbkVlIvOVQz2BYeRos-AlLpCligRhptte6ifEWiVphuTg-K6/s1600/collectionView.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqCOlOk8F-Uj2r-A9SjCn0Ca3AFE0ccEg07-ELUDbqHrXfcePJmirDXRPyVOlkD3tJ1bl1uhvKSe4ew15r7LnsB3-9d8JUDbkVlIvOVQz2BYeRos-AlLpCligRhptte6ifEWiVphuTg-K6/s320/collectionView.jpg" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Why we need UICollectionView?</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For years , iOS developers have used the UITableView component to create a huge variety of interfaces.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
But still if you want to present data in multiple columns, for example, you need to combine entire rows of data into a single cell.</div>
<div style="font-family: Helvetica; font-size: 12px;">
There is no way to make a UITableView scroll its content horizontally.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Well, apparently Apple realized this too, iOS 6 includes a new class called UICollectionView that is built to address theses shortcomings, Like a table view, this class lets you display a bunch of "cells" of data and will handle things like queueing up unused cells for later use. UICollectionView uses a halter class to do layout.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="text-decoration: underline;">At the abstract level, a collection view consists of four key elements</span></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Cells</div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Supplementary Views</div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Decoration Views</div>
<div style="font-family: Helvetica; font-size: 12px;">
4. Layout Object</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<span style="font-size: 12px;"><b>Cell</b> : </span>A cell is a representation of an item of data to be displayed (for example an image or a set of text based data).</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<span style="font-size: 12px;"><b>Supplementary Views</b> : </span>Supplementary views are objects that provide additional information about a section in a collection view. These are somewhat similar to section headers and footers in table views but are more general purpose and provide a greater level of flexibility in terms of positioning and content.</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<span style="font-size: 12px;"><b>Decoration Views</b> : </span>Decoration views can be used to provide a decorative background for the collection view which scrolls along with the content.</div>
<div style="font-family: Helvetica; font-size: 13px;">
Note - Standard Flow layout class does not support decoration views.</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<span style="text-decoration: underline;">So, Mainly three requirement for UICollectionView</span></div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
1. UICollectionViewDataSource</div>
<div style="font-family: Helvetica; font-size: 13px;">
2. UICollectionViewDelegate</div>
<div style="font-family: Helvetica; font-size: 13px;">
3. UICollectionViewFlowLayout</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<b>UICollectionViewDataSource</b> : The collection view instance needs a data source object from which to obtain the data items to be displayed.</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<b>UICollectionViewDelegate</b> : The collection view instance needs a delegate object to handle user interaction with the collection.</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px;">
<b>UICollectionViewFlowLayout</b> : The most important requirement for the UICollectionView class is a layout object to control the layout and organization of the cells.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
By default, the UICollectionViewFlowLayout class is used by instances of the UICollectionView class.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
Some Important classes and protocols for UICollectionView</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
1. UICollectionView class</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
2. UICollectionViewCell class</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
3. UICollectionViewFlowLayout class</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
4. UICollectionViewLayoutAttributes class</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
5. UICollectionViewDataSource protocol</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
6. UICollectionViewDelegate protocol</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
7. UICollectionViewFlowLayout protocol</div>
<div style="font-family: Helvetica; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>1. UICollectionView</b> : The UICollectionView class is responsible for managing the data items that are to be displayed to the user.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>2. UICollectionViewCell</b> : UICollectionViewCell class is responsible for displaying whatever data is provided to the UICollectionView instance by the data source with one cell corresponding to one data item.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
It has three parts </div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
2.1 Content View</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
2.2 SelectedBackground View</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
2.3 Background View</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj5BnUO81CZ6XZ9AzUpGLq3sFw-V72IKmiKNcKDkWXAcq_E5oS441DY0HGQkUXl15KOcm8IsbjcXYKC20wURNiK9KPwcb_j6pc2d7ZkUsj00cg7IWPygZ3ZpC5O9tDLvC-PPRXkmGfyYl5/s1600/Screen2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj5BnUO81CZ6XZ9AzUpGLq3sFw-V72IKmiKNcKDkWXAcq_E5oS441DY0HGQkUXl15KOcm8IsbjcXYKC20wURNiK9KPwcb_j6pc2d7ZkUsj00cg7IWPygZ3ZpC5O9tDLvC-PPRXkmGfyYl5/s320/Screen2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>3. UICollectionViewFlowLayout </b> : The UICollectionViewFlowLayout class is the default layout class for collection views and is designed to layout cells in a grid-like manner.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
By default, flow is implemented in a manner similar to that of “line wrapping” in a text editor.When one row of cells is full, the cells flow onto the next row and so on until all cells capable of fitting into the currently visible display region are visible. The flow layout class supports both horizontal and vertical scrolling configurable via the scrollDirection property. also supports the spacing between lines of cells in the grid.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>4. UICollectionViewLayoutAttributes</b> : Each item in a collection view has associated with it a set of attributes, below listed some important attributes</div>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>alpha</b> – the transparency of the item.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>center</b> – the location of the center of the item.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>frame</b> – the CGRect frame in which the item is displayed.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>hidden</b> – whether or not the item is currently visible.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>indexPath</b> – the index path location of the item in the collection view.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>representedElementCategory</b> – The type of item for which the attributes apply (i.e. for a cell, supplementary or decoration view).</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>size</b> – the size of the item.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>transform3D</b> – the current transform of the item. Attribute can be used to perform tasks such as rotating or scaling the item.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>zIndex</b> – controls the position of the item in the z axis</li>
</ul>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>5. UICollectionViewDataSource</b> : The UICollectionViewDataSource protocol needs to be implemented by the class responsible for supplying the collection view. This basically consists of a number of methods that define information such how many items of data are to be displayed, how the data is divided into different sections and, most importantly, supplies the collection view with the cell objects to be displayed.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
below listed some important methods</div>
<div style="color: #b51a00; font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
Mandatory Methods</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:numberOfItemsInSection:</b> - Returns the number of items to be displayed in the specified section of the collection view.</li>
</ul>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:cellForItemAtIndexPath : </b>This method is called by the collection view when it is ready to display a cell at the specified index path location in the collection view. It is required to return a cell object configured appropriately for the referenced index.</li>
</ul>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
Optional methods</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>numberOfSectionsInCollectionView:</b> - Indicates to the collection view the number of sections into which the collection view is to be divided.</li>
</ul>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:viewForSupplementaryElementOfKind:atIndexPath :</b>Called by the collection view to request a supplementary view of the specified kind. Returns an appropriately configured object to be displayed. In terms of the UICollectionViewFlowLayout class, the layout will request a supplementary view for either a header (UICollectionElementKindSectionHeader) or footer (UICollectionElementKindSectionFooter).</li>
</ul>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>6. UICollectionViewDelegate</b> : The UICollectionViewDelegate protocol defines a set of optional methods relate primarily to handling user interaction with the collection view elements (such as selecting a specific cell).</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
below listed some important methods</div>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:shouldSelectItemAtIndexPath:</b> - Returns a boolean value indicating whether the specified item is selectable by the user.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:didSelectItemAtIndexPath:</b> - Called by the collection view when the specified item has been selected by the user.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:shouldDeselectItemAtIndexPath:</b> - Returns a boolean value to indicate whether the specified item may be deselected by the user.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:didDeselectItemAtIndexPath:</b> - Called by the collection view when the specified item has been selected by the user.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:shouldHighlightItemAtIndexPath:</b> - Returns a boolean value indicating whether the specified item should be highlighted as a pre-cursor to possible selection by the user.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:didHighlightItemAtIndexPath:</b> - Called by the collection view when the specified item has been highlighted.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:didUnhighlightItemAtIndexPath:</b> - Called by the collection view when the specified item has been un-highlighted.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:didEndDisplayingCell:forItemAtIndexPath:</b> - Called by the collection view when the specified cell has been removed from the collection view.<b><span class="Apple-tab-span" style="white-space: pre;"> </span></b></li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><span style="font-family: 'Lucida Grande';"><b></b></span><b>collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:</b> - Called by the collection view when the specified supplementary view has been removed from the collection view.</li>
</ul>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
<b>7. UICollectionViewFlowLayout</b> : The UICollectionViewFlowLayout class has a number of properties that can be set to globally set default characteristics for items within a collection view (for example item spacing, line spacing, inter-cell spacing, supplementary view header and footer sizing etc).</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 6px;">
below listed some important methods</div>
<ul style="list-style-type: square;">
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:layout:sizeForItemAtIndexPath:</b> - Required to return to the flow layout object the size attributes for the item at the specified index path.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:layout:insetForSectionAtIndex:</b> - Required to return the inset value for the specified collection view section.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:layout:minimumLineSpacingForSectionAtIndex:</b> - Required to return the inset value for the specified collection view section.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:layout:minimumInteritemSpacingForSectionAtIndex:</b> - Required to return the interim spacing between cells in a row for the specified collection view section.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:layout:referenceSizeForHeaderInSection:</b> - Required to return the size for the header supplementary view for specified collection view section. Note that if a size is not specified, the view will not appear.</li>
<li style="font-family: Helvetica; font-size: 13px; margin: 0px 0px 1px;"><b>collectionView:layout:referenceSizeForFooterInSection:</b> - Required to return the size for the footer supplementary view for specified collection view section. Note that if a size is not specified, the view will not appear.</li>
</ul>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px;">
So this is what Apple guys added new Lib class added for iOS developer</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px;">
You may love to go for Simple Tutorial for UICollectionView I have created for beginner.</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px;">
or soon I'll add Advance UICollectionView Tutorial here, so stay tune with me :)</div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 13px; margin-bottom: 1px;">
I would love here your thoughts!!</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-17060474108600971862013-03-05T02:58:00.001-08:002013-03-05T03:11:20.151-08:00Convert String to Base64 in iOS Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Convert String to Base64 in iOS Tutorial</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
To all the iOS Developers!! This time I would like to share one small but important stuff,</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
How to encode Plain Text to base64 string and </div>
<div style="font-family: Helvetica; font-size: 12px;">
again convert base64 string to our original Plain Text string.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : This Application Developed Using : iOS 6</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In this Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Product Name : <b>Base64Demo</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Organization Name :<b>RDCWorld</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Company Identifier : <b>com.rdcworld</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave it blank for now)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Devices : <b>iPhone</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLDNdFyWOKM13TkEay5oPuZDmTOzfUxi0uY0GREGjP2GDUWlMn3MvdfObenYh-ALDaG3uLWLHPQ6DX6UjxgmYQoZfiGqn-qVLF0WFD0MViAf9LVdMM0jWObV5n2DzTZCPfmeTuKMzu5WCy/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLDNdFyWOKM13TkEay5oPuZDmTOzfUxi0uY0GREGjP2GDUWlMn3MvdfObenYh-ALDaG3uLWLHPQ6DX6UjxgmYQoZfiGqn-qVLF0WFD0MViAf9LVdMM0jWObV5n2DzTZCPfmeTuKMzu5WCy/s320/Screen+2.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For using base64 encoding we need to use "<span style="color: #d12f1b; font-family: Menlo; font-size: 11px;">NSData+Base64</span>" lib files in our application (say thanks to <span style="color: #008400; font-family: Menlo; font-size: 11px;">Matt Gallagher </span><span style="font-family: Menlo; font-size: 11px;">who made this easy</span>)</div>
<div style="font-family: Helvetica; font-size: 12px;">
so let's do it first.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. download base64 lib file from here (http://projectswithlove.com/projects/NSData_Base64.zip)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you will find (NSData+Base64. {h,m} ) files in downloaded folder </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5R1tx8oEwtSsTn40Ko4WkY33KRXy-BjxOPH8r4ECdQtW2hZCGVBz06Jzm-mpTlqAuhL3QUv5T7GQyBwmtZKy3MK2Mo1CBL3eFA_c5AnOqid-MyNoQDvoahDYhRXE-RZzhJn-B2LEu3_Hx/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="169" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5R1tx8oEwtSsTn40Ko4WkY33KRXy-BjxOPH8r4ECdQtW2hZCGVBz06Jzm-mpTlqAuhL3QUv5T7GQyBwmtZKy3MK2Mo1CBL3eFA_c5AnOqid-MyNoQDvoahDYhRXE-RZzhJn-B2LEu3_Hx/s320/Screen+3.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Just drag these two files to your project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
NSData+Base64.h</div>
<div style="font-family: Helvetica; font-size: 12px;">
NSData+Base64.m</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time our project structure is look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzEDCQRmUxMH_5TVqhNdd3l0MQNWfe-2j-qpIzQSlpp0uAaxFm7kj8-qaFoMZxV9Y58pvTomPlpEbltBrKLQm0FvbXAG9yWCLEN-D1XuRewMShMWyb6SpqH1FHLsZTkTqP58TTJ5IlgHrg/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzEDCQRmUxMH_5TVqhNdd3l0MQNWfe-2j-qpIzQSlpp0uAaxFm7kj8-qaFoMZxV9Y58pvTomPlpEbltBrKLQm0FvbXAG9yWCLEN-D1XuRewMShMWyb6SpqH1FHLsZTkTqP58TTJ5IlgHrg/s320/Screen+4.png" width="204" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : Newly added files contains (autorelease etc) so we need to disable ARC for these.</div>
<div style="font-family: Helvetica; font-size: 12px;">
do this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 Select Project (or click on Blue icon in Top Left side)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Go to --> Build Phases --> Compile Sources --> Click on Arrow to expend it </div>
<div style="font-family: Helvetica; font-size: 12px;">
3. now double click on NSData+Base64.m file and put "<b>-fno-objc-arc</b>" in popup window.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxzHWAeLatEgXnmn8uSpvaCb6tO-phebeL4UWFwWZ775cFM8YW-qrkQVvsNYSBrF_8f3l3-p5J6vPpq12OLg3PgzX7hlIRM4O0h0kmhqU7g0CAP1JlO8RprS3LNeStHQb9AbcXjddZy9nV/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxzHWAeLatEgXnmn8uSpvaCb6tO-phebeL4UWFwWZ775cFM8YW-qrkQVvsNYSBrF_8f3l3-p5J6vPpq12OLg3PgzX7hlIRM4O0h0kmhqU7g0CAP1JlO8RprS3LNeStHQb9AbcXjddZy9nV/s320/Screen+5.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add couple of UILabels and buttons, and a TextFields on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
UITextField : for taking input message from user</div>
<div style="font-family: Helvetica; font-size: 12px;">
UILabel : for showing converted results</div>
<div style="font-family: Helvetica; font-size: 12px;">
UIButton : for convert our message stuff</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Title bar : just drag UINavigation bar, double click on it , and give it title as "Base64 Encode-Decode" (we are using it as just simple Title bar )</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.drag UITextField, resize it and give it's Placeholder value as "enter message here" (you can find it on top right side in Attribute Inspector tab)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. drag UILabels and buttons and put the text as shown in below picture </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigPqofKrgI1clahXwrVESm4qRdIfZhRBTYoVPikoZ90Mzw-vctOG9TmI9DPYfHDHJPXf-m8M1PE4704x1-xtpHOejEyrQgKV7dyGIzZ8uY9y_ivYiNzMDpK5BWcmsQSUhM2LKep01R4Xm1/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigPqofKrgI1clahXwrVESm4qRdIfZhRBTYoVPikoZ90Mzw-vctOG9TmI9DPYfHDHJPXf-m8M1PE4704x1-xtpHOejEyrQgKV7dyGIzZ8uY9y_ivYiNzMDpK5BWcmsQSUhM2LKep01R4Xm1/s320/Screen+6.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UITextField,UILabel and IBAction method for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Fist is First, Create IBOutlet for UITextField,UILabel</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So now just Select UITextField --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifBOSouDjnEpwrqFQlLPxN3oetvEUlAigfgSjGuTqqVHTJuZ9zz1LdY0OOjg3-eWVfBlLAH_Vf30fKtHvX1MmtFNsY5EtT-rVMxEUmFlMuYAPX8iyCr1K64RA_mCaPMpzhmdBhCaufChgg/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifBOSouDjnEpwrqFQlLPxN3oetvEUlAigfgSjGuTqqVHTJuZ9zz1LdY0OOjg3-eWVfBlLAH_Vf30fKtHvX1MmtFNsY5EtT-rVMxEUmFlMuYAPX8iyCr1K64RA_mCaPMpzhmdBhCaufChgg/s320/Screen+8.png" width="320" /></a></div>
<br />
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">messageTextField</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG8Mk5ysA7MaYD9Ctf5uaqHVJoWgZHVSJKWw2dSRWTNuurFVcLGjpLjXqLQbLAWtmIUDrDtpVX1BXdPd1QkJMQqYzOMFw0xlMdlSN9XYMzYS3N95FwVEAvrJV2I1G8ywAreqSiC91k3R3d/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="96" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG8Mk5ysA7MaYD9Ctf5uaqHVJoWgZHVSJKWw2dSRWTNuurFVcLGjpLjXqLQbLAWtmIUDrDtpVX1BXdPd1QkJMQqYzOMFw0xlMdlSN9XYMzYS3N95FwVEAvrJV2I1G8ywAreqSiC91k3R3d/s320/Screen+9.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now you can see below code line in your ViewController.h file (in right side)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *messageTextField;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
do the same for UILabels (one by one) i have selected both Labels to make you clear (where they are on layout). give the name "<span style="font-family: Menlo; font-size: 11px;">resultBase64Label</span>" and "<span style="font-family: Menlo; font-size: 11px;">resultPlainTextLabel</span>" respectively.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK1MU9D0mresF9x5KB5kARIetQtwkbxeutkZTiGJmDcT9ypfFPVVxoC3VbRqJGmBfGWKOZueUW0imKDan8xzNevCjnP65vTvNTisKjIZ9BgI11tiWGdAHohaPQcpP2_dKBzvzHohijZhcE/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK1MU9D0mresF9x5KB5kARIetQtwkbxeutkZTiGJmDcT9ypfFPVVxoC3VbRqJGmBfGWKOZueUW0imKDan8xzNevCjnP65vTvNTisKjIZ9BgI11tiWGdAHohaPQcpP2_dKBzvzHohijZhcE/s1600/Screen+10.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
after adding IBOutlet for both Labels you can see two more line added to your header file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UILabel</span><span style="color: black;"> *resultBase64Label;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">weak</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #bb2ca2;">IBOutlet</span> <span style="color: #703daa;">UILabel</span> *resultPlainTextLabel;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Now Create IBAction for UIButtons.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Right click on UIButton <b>Convert to Base64</b> on Layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "Touch Up Inside" in <span style="color: #4f7a28;">Send Event </span>option and drag to header file this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQSaK_tAxLuqymGMQNqfebvpeKY8BhNpke84olDrct4F7173NFMRtEY8wVExRbSFtuY6TrEYmP7hdLbXwJCKIfqwD1OGvTpldEdyOSG4avPBlquq2t1JbDS1iIvyDbPOAnvIA13m7CVwMU/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQSaK_tAxLuqymGMQNqfebvpeKY8BhNpke84olDrct4F7173NFMRtEY8wVExRbSFtuY6TrEYmP7hdLbXwJCKIfqwD1OGvTpldEdyOSG4avPBlquq2t1JbDS1iIvyDbPOAnvIA13m7CVwMU/s320/Screen+11.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px;">
just put the Name : <span style="font-family: Menlo; font-size: 11px;"><b>convertToBase64</b></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and click on Connect button.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrtMyoM2qXmKkSR0ZAP1ZPVLrLDmALkT7apA9Z6T3l3Ww1sQ13BkmuwBQngXOxGpaa9Dg_qNaI7GeOQ9R-qu2FvupCMBPCJYrhh5c1sfdNtuIi9zp2FWRmgVIDVIPrdkAhaZSPuieBzEpE/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="102" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrtMyoM2qXmKkSR0ZAP1ZPVLrLDmALkT7apA9Z6T3l3Ww1sQ13BkmuwBQngXOxGpaa9Dg_qNaI7GeOQ9R-qu2FvupCMBPCJYrhh5c1sfdNtuIi9zp2FWRmgVIDVIPrdkAhaZSPuieBzEpE/s320/Screen+12.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now do the same for next UIButton <b>Convert to Plain Text</b> and give the name in popup window as "<span style="font-family: Menlo; font-size: 11px;">convertToPlainText</span>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see two methods added in header file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToBase64:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToPlainText:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Save app, and open ViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.h file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Base64Demo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/5/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *messageTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UILabel</span><span style="color: black;"> *resultBase64Label;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">weak</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #bb2ca2;">IBOutlet</span> <span style="color: #703daa;">UILabel</span> *resultPlainTextLabel;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToBase64:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToPlainText:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">1. import </span><span style="color: #78492a;">#import </span>"NSData+Base64.h"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> messageTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultBase64Label;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultPlainTextLabel;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. you can see two empty methods here</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<i>convertToBase64</i> and <i>convertToPlainText</i></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
these methods we declared in header file using IBAction with Buttons</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
so update these two buttons code this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToBase64:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//keypad go back</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">messageTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *resultBase64String = [<span style="color: #bb2ca2;">self</span> base64Encode:messageTextField.text];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">resultBase64Label</span>.<span style="color: #703daa;">text</span> = resultBase64String;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToPlainText:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *resultPlainString = [<span style="color: #bb2ca2;">self</span> base64Decode:resultBase64Label.text];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">resultPlainTextLabel</span>.<span style="color: #703daa;">text</span> = resultPlainString;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Now add Heart of the Application : two methods we need for encoding and decoding </div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
base64Encode <span style="color: black;">and</span> base64Decode</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//convert plain text o base64</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSString</span> *)base64Encode:(<span style="color: #703daa;">NSString</span> *)plainText</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSData</span><span style="color: black;"> *plainTextData = [plainText </span>dataUsingEncoding<span style="color: black;">:</span>NSUTF8StringEncoding<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *base64String = [plainTextData <span style="color: #31595d;">base64EncodedString</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> base64String;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//convert base64 to plain text</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSString</span> *)base64Decode:(<span style="color: #703daa;">NSString</span> *)base64String</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSData</span> *plainTextData = [<span style="color: #703daa;">NSData</span> <span style="color: #31595d;">dataFromBase64String</span>:base64String];</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *plainText = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithData<span style="color: black;">:plainTextData </span>encoding<span style="color: black;">:</span>NSUTF8StringEncoding<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> plainText;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.m file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Base64Demo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/5/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"NSData+Base64.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> messageTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultBase64Label;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resultPlainTextLabel;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToBase64:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//keypad go back</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">messageTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *resultBase64String = [<span style="color: #bb2ca2;">self</span> <span style="color: #31595d;">base64Encode</span>:<span style="color: #4f8187;">messageTextField</span>.<span style="color: #703daa;">text</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">resultBase64Label</span>.<span style="color: #703daa;">text</span> = resultBase64String;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)convertToPlainText:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *resultPlainString = [<span style="color: #bb2ca2;">self</span> <span style="color: #31595d;">base64Decode</span>:<span style="color: #4f8187;">resultBase64Label</span>.<span style="color: #703daa;">text</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">resultPlainTextLabel</span>.<span style="color: #703daa;">text</span> = resultPlainString;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - base64 methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//convert plain text o base64</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSString</span> *)base64Encode:(<span style="color: #703daa;">NSString</span> *)plainText</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSData</span><span style="color: black;"> *plainTextData = [plainText </span>dataUsingEncoding<span style="color: black;">:</span>NSUTF8StringEncoding<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *base64String = [plainTextData <span style="color: #31595d;">base64EncodedString</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> base64String;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//convert base64 to plain text</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #703daa;">NSString</span> *)base64Decode:(<span style="color: #703daa;">NSString</span> *)base64String</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSData</span> *plainTextData = [<span style="color: #703daa;">NSData</span> <span style="color: #31595d;">dataFromBase64String</span>:base64String];</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *plainText = [[</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithData<span style="color: black;">:plainTextData </span>encoding<span style="color: black;">:</span>NSUTF8StringEncoding<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> plainText;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Base64Demo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/5/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Base64Demo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 3/5/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : we could add so many things in this app (string validation on button click bla bla.. but I wanted it to be simple as it can be) .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVIqFizkjGiq7lhRvDx75Fbu9F5xfXSprocxcgx5aeydQpypYN6bEn1YEhE6SdmIwWJvN64-uznfHr7EPYpWRBW5Ri9B0igrpPVa19tP7SnRHUGnq7JloFeI1P5VFziBlK0E5Qw0snE2Rq/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVIqFizkjGiq7lhRvDx75Fbu9F5xfXSprocxcgx5aeydQpypYN6bEn1YEhE6SdmIwWJvN64-uznfHr7EPYpWRBW5Ri9B0igrpPVa19tP7SnRHUGnq7JloFeI1P5VFziBlK0E5Qw0snE2Rq/s320/Screen+13.png" width="223" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. It was so simple because <span style="color: #008400; font-family: Menlo; font-size: 11px;">Matt Gallagher</span> did everything for us.</div>
<div style="font-family: Helvetica; font-size: 12px;">
we just made it alive.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <a href="https://www.opendrive.com/files?M181OTMxOTA1X3RvTnRD" target="_blank"><b><span style="color: #38761d;">Base64Demo</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-38157946159369174382013-02-28T07:01:00.000-08:002013-03-05T02:52:41.982-08:00Get Current Location in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Happy Time to all Apple Family :)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Today we will learn how to Get Current Location in iPhone using GPS.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b><span style="color: red;">Note : This Application Developed Using : iOS 6</span></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In this Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Product Name : <b>CoreLocationDemo</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Organization Name :<b>RDCWorld</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Company Identifier : <b>com.rdcworld</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave it blank for now)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Devices : <b>iPhone</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: red;"><i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTdLwAmk9pdKANqIx0fj_VwDdhzrG0-T5u0-SHwIN-ZvmV_dWyQ-rYukjrQUX5xkVJLPJBjs2KRNphkEm0Xjiw4cHJJbi-bK_QLTUU3PHuptZm6Kmcc1KO34oT9xdyVsiRkqkKvVkDYmEg/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTdLwAmk9pdKANqIx0fj_VwDdhzrG0-T5u0-SHwIN-ZvmV_dWyQ-rYukjrQUX5xkVJLPJBjs2KRNphkEm0Xjiw4cHJJbi-bK_QLTUU3PHuptZm6Kmcc1KO34oT9xdyVsiRkqkKvVkDYmEg/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode dashboard .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For using GPS stuff we need to use "<b>CoreLocation.framework</b>" in our application</div>
<div style="font-family: Helvetica; font-size: 12px;">
so let's do it first.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Select Project (or click on Blue icon in Top Left side)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Go to --> Build Phases --> Link Binary With Libraries > Click on Arrow to expend it --> click on (+) to add</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. in Popup window look for "CoreLocation" this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3Q_kQxN2IAtTiHAci2eODqmo8KoVtYdqPVx_PS2jpbHe98eue3QIKMcPrthjipKW8L93h4oncJxo4rRZqbBaNyFS6P5TisXZkw6rbJDn896i5EbWWHSRexi66YZ1TW-PCIcBE90jtcyuq/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3Q_kQxN2IAtTiHAci2eODqmo8KoVtYdqPVx_PS2jpbHe98eue3QIKMcPrthjipKW8L93h4oncJxo4rRZqbBaNyFS6P5TisXZkw6rbJDn896i5EbWWHSRexi66YZ1TW-PCIcBE90jtcyuq/s320/Screen+3.png" width="284" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select framework and click <b>Add</b> button.</div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Framework added in our project (a Yellow Suitcase icon ).</div>
<div style="font-family: Helvetica; font-size: 12px;">
so just drag it to below in Frameworks Group (Folder)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is our project structure look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCWIR0zZLJRN6SvUKNIWIN7O02PvPpe0FiEMbfTc89U5Ej48lr3EaXOczneeKlyyJmSBQKKF6W8d0456q5mA6VHpT2bsoYtoXgQCJevCqLRcV4dZe-xLAd3yniZEXOsrzpg1Fj8lSo8wtK/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCWIR0zZLJRN6SvUKNIWIN7O02PvPpe0FiEMbfTc89U5Ej48lr3EaXOczneeKlyyJmSBQKKF6W8d0456q5mA6VHpT2bsoYtoXgQCJevCqLRcV4dZe-xLAd3yniZEXOsrzpg1Fj8lSo8wtK/s320/Screen+4.png" width="198" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add UILabel and button on our screen.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
UILabel : for showing GPS information.</div>
<div style="font-family: Helvetica; font-size: 12px;">
UIButton : for requesting GPS information with the help of CLLocationManager.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now drag one UILabel, double click on it update default name to "Press Button to get Location"</div>
<div style="font-family: Helvetica; font-size: 12px;">
you may like to increase its size as shown in picture.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
then same way drag UIButton to Our Layout from Object Lib ( Object Lib you can see in Bottom Right corner)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Give button name as "Get Current Location"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
See our layout looking like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG0cbbZx0fsmdSjVqFYgE4I1Zrq4HzOyB7tlZ_CpnTAYlpuDQ8mNetQGos24Ktu4tyEA5d3CTxRYw4-yBvUMVEFOzvVD3vclGitFRm4oyaviSy15XP_n5nIWeVz2FUS1qjSF3jnkS8E8yb/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG0cbbZx0fsmdSjVqFYgE4I1Zrq4HzOyB7tlZ_CpnTAYlpuDQ8mNetQGos24Ktu4tyEA5d3CTxRYw4-yBvUMVEFOzvVD3vclGitFRm4oyaviSy15XP_n5nIWeVz2FUS1qjSF3jnkS8E8yb/s320/Screen+5.png" width="219" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UILabel and IBAction method for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Fist is First, Create IBOutlet for UILabel</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So now just Select UILabel --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlV4yLyhqXlQCShNAHQN7JV_iL2gUo8FTQ8Ekhg5cYRUnGkXfsGShESJyqSOzr8GAbxzIgh4jjBezXsu9qSB_AojVEyci6dkm8tvp6bPkQ6Zem0JeszjTgBJPqBwZPjtSIOURBhs7WWNNN/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlV4yLyhqXlQCShNAHQN7JV_iL2gUo8FTQ8Ekhg5cYRUnGkXfsGShESJyqSOzr8GAbxzIgh4jjBezXsu9qSB_AojVEyci6dkm8tvp6bPkQ6Zem0JeszjTgBJPqBwZPjtSIOURBhs7WWNNN/s320/Screen+7.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">locationMessageLabel</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJsSQ9_Oy5waEAmpYb02wVaG0gc3uMbh8di1ihe7CiSgbP3Qw3fE2uOId-88tN5z04NU6n7tksN9uUdGlkInvxaruJqwgvsmGVGn2DsJ8c4rn43bI5N1KyDh0diswFVG9z1V64djbJ4iWg/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJsSQ9_Oy5waEAmpYb02wVaG0gc3uMbh8di1ihe7CiSgbP3Qw3fE2uOId-88tN5z04NU6n7tksN9uUdGlkInvxaruJqwgvsmGVGn2DsJ8c4rn43bI5N1KyDh0diswFVG9z1V64djbJ4iWg/s1600/Screen+8.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Create IBAction for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Right click on UIButton on Layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "Touch Up Inside" in Send Event option and drag to header file this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEwAh0ps9RH5bHhvakAMDrPCMrqOvLSMpqyekV5Fu5N45gA7XEecKdIwLWixdHxTHNDOd273VkZFgTi1V_VvBPmOkpj0A8Zt0SEitYDwqIfilMmoYY1iMKicB7hLEERt9RWckB3iIjEH_o/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="235" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEwAh0ps9RH5bHhvakAMDrPCMrqOvLSMpqyekV5Fu5N45gA7XEecKdIwLWixdHxTHNDOd273VkZFgTi1V_VvBPmOkpj0A8Zt0SEitYDwqIfilMmoYY1iMKicB7hLEERt9RWckB3iIjEH_o/s320/Screen+9.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px;">
just put the Name : getCurrentLocation</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and click on Connect button.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUUBRY9JKeVm78DvXZWvCWNJd1nTmGw4-m8JUK-wpYuyXgqSQQl-SxfpodphQ86OX2bA7cKp1cC9V-IkwV0OOkE4OK6eWSOdOoShA-TtvbvKRjv-B-gwo9EUobBJLNntuV7HgmsZxNPjUf/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUUBRY9JKeVm78DvXZWvCWNJd1nTmGw4-m8JUK-wpYuyXgqSQQl-SxfpodphQ86OX2bA7cKp1cC9V-IkwV0OOkE4OK6eWSOdOoShA-TtvbvKRjv-B-gwo9EUobBJLNntuV7HgmsZxNPjUf/s1600/Screen+10.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now agin back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Save app, and open ViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Import CoreLocation Lib header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><CoreLocation/CoreLocation.h></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Add delegate to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><</span>CLLocationManagerDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;">3. declare </span>CLLocationManager <span style="color: black;">and</span> CLLocation <span style="color: black;">instances</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">retain</span>) <span style="color: #703daa;">CLLocationManager</span> *locationManager;</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">CLLocation</span><span style="color: black;"> *latestLocation;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.h file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreLocationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><CoreLocation/CoreLocation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>CLLocationManagerDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">weak</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #bb2ca2;">IBOutlet</span> <span style="color: #703daa;">UILabel</span> *locationMessageLabel;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">retain</span>) <span style="color: #703daa;">CLLocationManager</span> *locationManager;</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">CLLocation</span><span style="color: black;"> *latestLocation;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getCurrentLocation:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> locationMessageLabel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> locationManager;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> latestLocation;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. initialize location manager and start request for location updates in <span style="font-family: Menlo; font-size: 11px;"><b>viewDidLoad</b> method</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">locationManager</span><span style="color: black;"> = [[</span>CLLocationManager<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>locationManager<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//request for location updates</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">locationManager</span><span style="color: black;"> </span>startUpdatingLocation<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">3. implement </span>CLLocationManager Delegate's methods</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) locationManager:(<span style="color: #703daa;">CLLocationManager</span> *)manager didUpdateLocations:(<span style="color: #703daa;">NSArray</span> *)locations{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//we got the latest location info here</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">latestLocation</span> = [locations <span style="color: #3d1d81;">lastObject</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) locationManager:(<span style="color: #703daa;">CLLocationManager</span> *)manager didFailWithError:(<span style="color: #703daa;">NSError</span> *)error{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>locationMessageLabel<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = error.</span><span style="color: #3d1d81;">description</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. update <span style="font-family: Menlo; font-size: 11px;"><b>getCurrentLocation</b></span> method code this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getCurrentLocation:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">double</span><span style="color: black;"> lat = </span><span style="color: #4f8187;">latestLocation</span><span style="color: black;">.</span>coordinate<span style="color: black;">.</span>latitude<span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">double</span><span style="color: black;"> lon = </span><span style="color: #4f8187;">latestLocation</span><span style="color: black;">.</span>coordinate<span style="color: black;">.</span>longitude<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *gpsInfoMessage = [</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span><span style="color: #3d1d81;">stringWithFormat</span><span style="color: black;">:</span>@"GPS Details \n\n Latitude : %f \n Longitude : %f"<span style="color: black;">,lat,lon];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">locationMessageLabel</span>.<span style="color: #703daa;">text</span> = gpsInfoMessage;</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>locationMessageLabel<span style="color: black;">.</span><span style="color: #703daa;">numberOfLines</span><span style="color: black;"> = </span><span style="color: #272ad8;">0</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.m file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreLocationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> locationMessageLabel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> locationManager;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> latestLocation;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - View Controller's Life Cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">locationManager</span><span style="color: black;"> = [[</span>CLLocationManager<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>locationManager<span style="color: black;">.</span><span style="color: #703daa;">delegate</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//request for location updates</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">locationManager</span><span style="color: black;"> </span>startUpdatingLocation<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button click method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getCurrentLocation:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">double</span><span style="color: black;"> lat = </span><span style="color: #4f8187;">latestLocation</span><span style="color: black;">.</span>coordinate<span style="color: black;">.</span>latitude<span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">double</span><span style="color: black;"> lon = </span><span style="color: #4f8187;">latestLocation</span><span style="color: black;">.</span>coordinate<span style="color: black;">.</span>longitude<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *gpsInfoMessage = [</span><span style="color: #703daa;">NSString</span><span style="color: black;"> </span><span style="color: #3d1d81;">stringWithFormat</span><span style="color: black;">:</span>@"GPS Details \n\n Latitude : %f \n Longitude : %f"<span style="color: black;">,lat,lon];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">locationMessageLabel</span>.<span style="color: #703daa;">text</span> = gpsInfoMessage;</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>locationMessageLabel<span style="color: black;">.</span><span style="color: #703daa;">numberOfLines</span><span style="color: black;"> = </span><span style="color: #272ad8;">0</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - CLLocationManager Delegate's methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) locationManager:(<span style="color: #703daa;">CLLocationManager</span> *)manager didUpdateLocations:(<span style="color: #703daa;">NSArray</span> *)locations{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//we got the latest location info here</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">latestLocation</span> = [locations <span style="color: #3d1d81;">lastObject</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) locationManager:(<span style="color: #703daa;">CLLocationManager</span> *)manager didFailWithError:(<span style="color: #703daa;">NSError</span> *)error{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>locationMessageLabel<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = error.</span><span style="color: #3d1d81;">description</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreLocationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CoreLocationDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Application life cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//leave all rest methods for now</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : Make sure you have to Run application using Apple's Real Device (iPhone, iPod, and iPad etc.), you can't get best results in simulator.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXHmbwLgckMTWWZ1j4Z58B3oyAO-33DUjlDLL34tUzCVKEArYfLiGV32-eKqteuJpn6tIzM-HUKk0FA-In8FX_FUTClaSjDFHOv6RcyyLC35iVZiL5Ws8GG51z9LAiN33rXKU0U47U4Q5D/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXHmbwLgckMTWWZ1j4Z58B3oyAO-33DUjlDLL34tUzCVKEArYfLiGV32-eKqteuJpn6tIzM-HUKk0FA-In8FX_FUTClaSjDFHOv6RcyyLC35iVZiL5Ws8GG51z9LAiN33rXKU0U47U4Q5D/s320/Screen+12.png" width="224" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You need to Allow it "Use Current Location"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1eNSYHgSWJ6JVeUhnrMMnyPVaOIJx0XvROCvwr1pnFZgUaygthTGhvDnKwJvKTT21ome9touI1iiGGPT3EZWSdl-h00iKSRYp2pl5LI5GMWXAf9iz3DmOhh2X8CXAwe73vtFnCBqKYc9D/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1eNSYHgSWJ6JVeUhnrMMnyPVaOIJx0XvROCvwr1pnFZgUaygthTGhvDnKwJvKTT21ome9touI1iiGGPT3EZWSdl-h00iKSRYp2pl5LI5GMWXAf9iz3DmOhh2X8CXAwe73vtFnCBqKYc9D/s320/Screen+13.png" width="215" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. It was so simple because Apple doing everything for us.</div>
<div style="font-family: Helvetica; font-size: 12px;">
we just made it alive.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <a href="https://www.opendrive.com/files?M181OTMxODUyXzRRZUFN" target="_blank"><b><span style="color: #38761d;">CoreLocationDemo</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thought !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-4632098302904876352013-02-28T03:29:00.003-08:002013-03-05T02:51:47.406-08:00Pick Image From Gallery iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
In this app we will pick photo from Camera Roll (Image Gallery) and use it on UIImageView.</div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by ..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can a Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVVDJ_AhIvmfQLFFGDGAdBkQg_IjzfHSbrkGJKyRZH8-9hOZI1WqlxaRgvWbLh9BtDGfaZXVxehdsqS_4gKnyjFNOIfqfG38jbXMQd4sCq6zbKznYGaWoDbHyVJAWGZ_TD4hG_Pll8n5rU/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVVDJ_AhIvmfQLFFGDGAdBkQg_IjzfHSbrkGJKyRZH8-9hOZI1WqlxaRgvWbLh9BtDGfaZXVxehdsqS_4gKnyjFNOIfqfG38jbXMQd4sCq6zbKznYGaWoDbHyVJAWGZ_TD4hG_Pll8n5rU/s320/Screen+1.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In this Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Product Name : PickGalleryImage</div>
<div style="font-family: Helvetica; font-size: 12px;">
Organization Name :RDCWorld</div>
<div style="font-family: Helvetica; font-size: 12px;">
Company Identifier : com.rdcworld</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave it blank for now)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Devices : iPhone</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggnyVmM0kj1SYlegjSDf8rU52SZ6Ge62VLt4fotyMRRFucjPMVVHKP-M5Hd3_j-jdUTqcTl5Y3DJEscv6OB4v4gpbJAVRWLOKC1gOfH7GNeefZ01aDkZv-3iN-VkvVhwQD3USA8qGGRKxd/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggnyVmM0kj1SYlegjSDf8rU52SZ6Ge62VLt4fotyMRRFucjPMVVHKP-M5Hd3_j-jdUTqcTl5Y3DJEscv6OB4v4gpbJAVRWLOKC1gOfH7GNeefZ01aDkZv-3iN-VkvVhwQD3USA8qGGRKxd/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is our project structure look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijb5eGY3dN-_ySu6KjHkHg5JPJWUerGQ9USlNY2VfHyGKavTYwlxbqMK5hcOhLGfGaaRawkfgQBPNUDgMLN_a4mRCPeGc_8W4W-gN50EFYvXegtyUp4lEi_miMx3koktO7LjdQ7bUh9BUj/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijb5eGY3dN-_ySu6KjHkHg5JPJWUerGQ9USlNY2VfHyGKavTYwlxbqMK5hcOhLGfGaaRawkfgQBPNUDgMLN_a4mRCPeGc_8W4W-gN50EFYvXegtyUp4lEi_miMx3koktO7LjdQ7bUh9BUj/s320/Screen+3.png" width="198" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add Image view and button on our screen.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
UIImageView : for showing picked image.</div>
<div style="font-family: Helvetica; font-size: 12px;">
UIButton : for open camera Roll to capture image.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now drag on UIImage View and UIButton to Our Layout from Object Lib ( Object Lib you can see in Bottom Right corner)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
See our layout looking like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdv3paozv41VWlOVDRZnl6yT23_aawWA3h5iGeFlOb6P1p05-TyY5NDb2BPqb4UGkMYHQoIAYQkYuO4tV5BMLRkaBeZ-miVJLX9Yzvzz_5AYeY17v4TWhrfucmQEGCP_rBVcN6MXRqIsor/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdv3paozv41VWlOVDRZnl6yT23_aawWA3h5iGeFlOb6P1p05-TyY5NDb2BPqb4UGkMYHQoIAYQkYuO4tV5BMLRkaBeZ-miVJLX9Yzvzz_5AYeY17v4TWhrfucmQEGCP_rBVcN6MXRqIsor/s320/Screen+4.png" width="222" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UIImageView and IBAction method for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Fist is First, Create IBOutlet for UIImageView</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So now just Select UIImageView --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgPeWJ_5-W9EF7IRERYFTB7d3BofRChn53H08xQ7nRsAF80yzcdPb5PRhv_8Ocig4ZltqBnUeb8-gjdXvcldYDmvWAwdbCKC0Igedz-T7M_igEV6UynBqskaRxmf-Ugrgdjq_23Btb4bp7/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgPeWJ_5-W9EF7IRERYFTB7d3BofRChn53H08xQ7nRsAF80yzcdPb5PRhv_8Ocig4ZltqBnUeb8-gjdXvcldYDmvWAwdbCKC0Igedz-T7M_igEV6UynBqskaRxmf-Ugrgdjq_23Btb4bp7/s1600/Screen+6.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtXJRfmlcnm27WDKO8cSD5E6euvKl3An2oOBZ1TJgZnIEDMtiKrrtnbJK03p4Bu-pHrchVj-qWUCW8wNqfUlB30Vu_dai182XgMWFrefHyUbJbvGaQaGNAo4Jc5puPzIyxhHiDxo2TQHpc/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtXJRfmlcnm27WDKO8cSD5E6euvKl3An2oOBZ1TJgZnIEDMtiKrrtnbJK03p4Bu-pHrchVj-qWUCW8wNqfUlB30Vu_dai182XgMWFrefHyUbJbvGaQaGNAo4Jc5puPzIyxhHiDxo2TQHpc/s320/Screen+7.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "imageView" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZGhtvpdZDmF-f6auf81tsAv17RCCZvkwKR1VEito0XBMxk0DiZBex8n7kQ5mpzBrIqa3YlPo5lkOrmy450K-S1zxQB7HU0iOYCZhB-87v_dwTVL2EHPF-KiCA4I8tAwtSt3blLlRISDLJ/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZGhtvpdZDmF-f6auf81tsAv17RCCZvkwKR1VEito0XBMxk0DiZBex8n7kQ5mpzBrIqa3YlPo5lkOrmy450K-S1zxQB7HU0iOYCZhB-87v_dwTVL2EHPF-KiCA4I8tAwtSt3blLlRISDLJ/s1600/Screen+8.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Create IBAction for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Right click on UIButton on Layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "Touch Up Inside" in Send Event option and drag to header file this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnQLEhc5PADrY1xlm7oFO_PwJ3LgMH5cTSM7w6QYJDA6j1p5ivydHQvGPp1hisdzNoA4HQxRC-V-9mG4KnEjtVWyiVRmRRrAkyeT4k0EaLYF0yHoqxfQAfHqd9U5f4iaOPmfYV4ux5xoFC/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnQLEhc5PADrY1xlm7oFO_PwJ3LgMH5cTSM7w6QYJDA6j1p5ivydHQvGPp1hisdzNoA4HQxRC-V-9mG4KnEjtVWyiVRmRRrAkyeT4k0EaLYF0yHoqxfQAfHqd9U5f4iaOPmfYV4ux5xoFC/s320/Screen+9.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px;">
just put the Name : openCameraRoll</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and click on Connect button.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6U9RdsnahayVb0vNlJnkyv8wNxlrWODPIDkX-BwId_Kb2yv5VxupyfOnsgngIps9_petTqlG_k33boV7lLHa1ilVHLsDaUj5lzhlx1Ih2px7bsrAbLkozWjRoV_-QsKncYyBjwMA3QqiK/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="147" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6U9RdsnahayVb0vNlJnkyv8wNxlrWODPIDkX-BwId_Kb2yv5VxupyfOnsgngIps9_petTqlG_k33boV7lLHa1ilVHLsDaUj5lzhlx1Ih2px7bsrAbLkozWjRoV_-QsKncYyBjwMA3QqiK/s320/Screen+10.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now agin back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Save app, and open ViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
add these two delegates to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><</span>UIImagePickerControllerDelegate<span style="color: black;">,</span>UINavigationControllerDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.h file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
///</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// PickGalleryImage</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UIImagePickerControllerDelegate<span style="color: black;">,</span>UINavigationControllerDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIImageView</span><span style="color: black;"> *imageView;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)openCameraRoll:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
add synthesize for imageView just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> imageView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
update openCameraRoll method code this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)openCameraRoll:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UIImagePickerController<span style="color: black;"> * picker = [[</span>UIImagePickerController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>picker.<span style="color: #703daa;">delegate</span> = <span style="color: #bb2ca2;">self</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> picker.</span><span style="color: #703daa;">sourceType</span><span style="color: black;"> = </span>UIImagePickerControllerSourceTypePhotoLibrary<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//start camera view</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>presentViewController<span style="color: black;">:picker </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Add <span style="color: #703daa;">UIImagePickerController's </span>delegate method to handle camera event</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)imagePickerController:(<span style="color: #703daa;">UIImagePickerController</span> *)picker didFinishPickingMediaWithInfo:(<span style="color: #703daa;">NSDictionary</span> *)info {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [picker </span>dismissViewControllerAnimated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #4f8187;">imageView</span><span style="color: black;">.</span><span style="color: #703daa;">image</span><span style="color: black;"> = [info </span><span style="color: #3d1d81;">objectForKey</span><span style="color: black;">:</span>@"UIImagePickerControllerOriginalImage"<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.m file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// PickGalleryImage</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> imageView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's life cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//Open Camera Roll button click method</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)openCameraRoll:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UIImagePickerController<span style="color: black;"> * picker = [[</span>UIImagePickerController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>picker.<span style="color: #703daa;">delegate</span> = <span style="color: #bb2ca2;">self</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> picker.</span><span style="color: #703daa;">sourceType</span><span style="color: black;"> = </span>UIImagePickerControllerSourceTypePhotoLibrary<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//start camera view</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>presentViewController<span style="color: black;">:picker </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UIImagePickerController's delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//this method get called when we click on USE button after capturing image</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)imagePickerController:(<span style="color: #703daa;">UIImagePickerController</span> *)picker didFinishPickingMediaWithInfo:(<span style="color: #703daa;">NSDictionary</span> *)info {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [picker </span>dismissViewControllerAnimated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #4f8187;">imageView</span><span style="color: black;">.</span><span style="color: #703daa;">image</span><span style="color: black;"> = [info </span><span style="color: #3d1d81;">objectForKey</span><span style="color: black;">:</span>@"UIImagePickerControllerOriginalImage"<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b>PHASE - IV (Run App)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : Make you have to Run application using Apple's Real Device (iPhone, iPod, and iPad etc.), you can't test camera app in simulator.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I clicked on <b>Open Camera Roll Button</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b><br /></b></div>
<div style="font-family: Helvetica; font-size: 12px;">
</div>
<span style="color: red;"><i>Note : We need to Allow to Access your photos here</i></span><br />
<br />
<div style="font-family: Helvetica; font-size: 12px;">
<b><br /></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz3L4Szhj-Q9ZkLdfq1pigop910-vNKFxEKfjarxYGHBrCvfe4VLnaS07SM4i1XEJQ32b7QYGH3wDcAh9R7J9MvULIZJlNITgVJ4ghDFpVg44XgXdh3fzURx8gMvpnO49ZxKdizCfzj5qr/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz3L4Szhj-Q9ZkLdfq1pigop910-vNKFxEKfjarxYGHBrCvfe4VLnaS07SM4i1XEJQ32b7QYGH3wDcAh9R7J9MvULIZJlNITgVJ4ghDFpVg44XgXdh3fzURx8gMvpnO49ZxKdizCfzj5qr/s320/Screen+12.png" width="221" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
then I Picked up one photo</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpb_2FKRdrrOZze2aKIvdhHiqK7xy6AkDZdUjyqIkG7DlCF1xwUiVEpIUnJl5CIzz5JfTByXbRjaejgd2buNGR3aer5DGHuxp0KVAhrG-BeYX3rV1AOld5egj_FK79Jc7PmA_mgdDY_MGR/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpb_2FKRdrrOZze2aKIvdhHiqK7xy6AkDZdUjyqIkG7DlCF1xwUiVEpIUnJl5CIzz5JfTByXbRjaejgd2buNGR3aer5DGHuxp0KVAhrG-BeYX3rV1AOld5egj_FK79Jc7PmA_mgdDY_MGR/s320/Screen+13.png" width="224" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. It was so simple because Apple doing everything for us.</div>
<div style="font-family: Helvetica; font-size: 12px;">
we just made it alive.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <a href="https://www.opendrive.com/files?M181OTMxNzA4XzV2czE4" target="_blank"><b><span style="color: #38761d;">PickGalleryImageiPhone</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thought !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-34762003074299513542013-02-28T02:07:00.000-08:002013-03-05T02:50:48.637-08:00Camera in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Camera in iPhone Tutorial</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
What's up Crazzy coders… \m/</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So you are looking for Playing with Camera stuff in you iPhone Application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! you landed up on the right planet.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Today we will write simple application to learn how to use Camera in our iPhone Application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Int this app we will capture photo using camera and use on UIImageView in our application</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by ..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can a Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In this Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Product Name : <b>CameraDemo</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Organization Name :<b>RDCWorld</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Company Identifier : <b>com.rdcworld</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave it blank for now)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Devices : <b>iPhone</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcywaDjCmHZHr4120czZ0SZ31TqXMa_Ajc51d-eJfbeh832-NkW0zNXj7KKGJfoaVM3sMTAGxv7mcD7ak3lk35YOfDhatJlD0AN2aJYk2LqLaYVhyphenhyphen4_r_9euJMnzIIme2fgbPZIm46Rzse/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="260" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcywaDjCmHZHr4120czZ0SZ31TqXMa_Ajc51d-eJfbeh832-NkW0zNXj7KKGJfoaVM3sMTAGxv7mcD7ak3lk35YOfDhatJlD0AN2aJYk2LqLaYVhyphenhyphen4_r_9euJMnzIIme2fgbPZIm46Rzse/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is our project structure look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizgyYv74Ipm-G-pGJ_ktCTb_6IrBysJH2bWQiP3k28izQCrBryJtbCFuSRwxFBiDiCgXNElFe5Cn9cQ4hD87EkUqV-3sJjzE8jJ-HXyjtpzw1ZE6ct7fAfqIhgvWGsOry0lyyfWqaAOCUZ/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizgyYv74Ipm-G-pGJ_ktCTb_6IrBysJH2bWQiP3k28izQCrBryJtbCFuSRwxFBiDiCgXNElFe5Cn9cQ4hD87EkUqV-3sJjzE8jJ-HXyjtpzw1ZE6ct7fAfqIhgvWGsOry0lyyfWqaAOCUZ/s320/Screen+3.png" width="193" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add Image view and button on our screen.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
UIImageView : for showing captured image.</div>
<div style="font-family: Helvetica; font-size: 12px;">
UIButton : for open camera to capture image.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now drag on UIImage View and UIButton to Our Layout from Object Lib ( Object Lib you can see in Bottom Right corner)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
See our layout looking like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfzKQXimNYA3vBIOAj72BR9t-NAj-7lS2vh_gGmbNS_d11Dwl1rMQIy1jNt2_V8TKGV7MZheXQKUSKJLLA5a4E-bFKGan-DebIx6nvemRPOGHkVohS_fip80VZbKRGbyefPgeigb1p-0Ok/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfzKQXimNYA3vBIOAj72BR9t-NAj-7lS2vh_gGmbNS_d11Dwl1rMQIy1jNt2_V8TKGV7MZheXQKUSKJLLA5a4E-bFKGan-DebIx6nvemRPOGHkVohS_fip80VZbKRGbyefPgeigb1p-0Ok/s320/Screen+4.png" width="222" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UIImageView and IBAction method for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Fist is First, Create IBOutlet for UIImageView</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So now just Select UIImageView --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgPeWJ_5-W9EF7IRERYFTB7d3BofRChn53H08xQ7nRsAF80yzcdPb5PRhv_8Ocig4ZltqBnUeb8-gjdXvcldYDmvWAwdbCKC0Igedz-T7M_igEV6UynBqskaRxmf-Ugrgdjq_23Btb4bp7/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgPeWJ_5-W9EF7IRERYFTB7d3BofRChn53H08xQ7nRsAF80yzcdPb5PRhv_8Ocig4ZltqBnUeb8-gjdXvcldYDmvWAwdbCKC0Igedz-T7M_igEV6UynBqskaRxmf-Ugrgdjq_23Btb4bp7/s1600/Screen+6.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtXJRfmlcnm27WDKO8cSD5E6euvKl3An2oOBZ1TJgZnIEDMtiKrrtnbJK03p4Bu-pHrchVj-qWUCW8wNqfUlB30Vu_dai182XgMWFrefHyUbJbvGaQaGNAo4Jc5puPzIyxhHiDxo2TQHpc/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtXJRfmlcnm27WDKO8cSD5E6euvKl3An2oOBZ1TJgZnIEDMtiKrrtnbJK03p4Bu-pHrchVj-qWUCW8wNqfUlB30Vu_dai182XgMWFrefHyUbJbvGaQaGNAo4Jc5puPzIyxhHiDxo2TQHpc/s320/Screen+7.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "imageView" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZGhtvpdZDmF-f6auf81tsAv17RCCZvkwKR1VEito0XBMxk0DiZBex8n7kQ5mpzBrIqa3YlPo5lkOrmy450K-S1zxQB7HU0iOYCZhB-87v_dwTVL2EHPF-KiCA4I8tAwtSt3blLlRISDLJ/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZGhtvpdZDmF-f6auf81tsAv17RCCZvkwKR1VEito0XBMxk0DiZBex8n7kQ5mpzBrIqa3YlPo5lkOrmy450K-S1zxQB7HU0iOYCZhB-87v_dwTVL2EHPF-KiCA4I8tAwtSt3blLlRISDLJ/s1600/Screen+8.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Create IBAction for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Right click on UIButton on Layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "Touch Up Inside" in Send Event option and drag to header file this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSGdnwo_bGurk5WPN9H-loT5awy0CFnYXoAEbkYhKmNpaYOtSBgEeTogQxgiSUq3uzuMFRoMhtuEkxHtIpsFWVDxTzaGdnpdUDs2BvSb_GFcM3M4Ymy2xbO82Rr3E42S83SKRhyR08rwrq/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSGdnwo_bGurk5WPN9H-loT5awy0CFnYXoAEbkYhKmNpaYOtSBgEeTogQxgiSUq3uzuMFRoMhtuEkxHtIpsFWVDxTzaGdnpdUDs2BvSb_GFcM3M4Ymy2xbO82Rr3E42S83SKRhyR08rwrq/s1600/Screen+10.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwgD7eN5CjaSi-pIxmUGGRg1yOPEty4KJGznjEERLSoJZaA3CGRX6bpuKpik8gK2vkTwVoYHqB8W6GnZnANQ70cuQ9sXLfABDnqs0XuNvSoDboc1SqEVV-dkRpqRvNQSLZ1s7ljWT-ZUsm/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwgD7eN5CjaSi-pIxmUGGRg1yOPEty4KJGznjEERLSoJZaA3CGRX6bpuKpik8gK2vkTwVoYHqB8W6GnZnANQ70cuQ9sXLfABDnqs0XuNvSoDboc1SqEVV-dkRpqRvNQSLZ1s7ljWT-ZUsm/s320/Screen+9.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px;">
just put the Name : openCamera</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and click on Connect button.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSGdnwo_bGurk5WPN9H-loT5awy0CFnYXoAEbkYhKmNpaYOtSBgEeTogQxgiSUq3uzuMFRoMhtuEkxHtIpsFWVDxTzaGdnpdUDs2BvSb_GFcM3M4Ymy2xbO82Rr3E42S83SKRhyR08rwrq/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSGdnwo_bGurk5WPN9H-loT5awy0CFnYXoAEbkYhKmNpaYOtSBgEeTogQxgiSUq3uzuMFRoMhtuEkxHtIpsFWVDxTzaGdnpdUDs2BvSb_GFcM3M4Ymy2xbO82Rr3E42S83SKRhyR08rwrq/s1600/Screen+10.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Doble click on Button and change default name to "Open Camera"<br />
<br />
Done!! now agin back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgii_cJ4zY8h6V9DtPIyfST4BD8f_hzOXaalRzaU_M0xLpkXNK765YNfqRaj0guzvFtc9e1cskcAqLukuyNGlesdYfogXFSnu1oraUo2IfapVtcPluzXu9_N5TrTtFAVm7djk56_xRn-vO9/s1600/Screen+11.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Save app, and open ViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
add these two delegates to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><</span>UIImagePickerControllerDelegate<span style="color: black;">,</span>UINavigationControllerDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.h file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CameraDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> ViewController : </span>UIViewController<span style="color: black;"><</span>UIImagePickerControllerDelegate<span style="color: black;">,</span>UINavigationControllerDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIImageView</span><span style="color: black;"> *imageView;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)openCamera:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
add synthesize for imageView just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> imageView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
update openCamera method code this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)openCamera:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UIImagePickerController<span style="color: black;"> * picker = [[</span>UIImagePickerController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>picker.<span style="color: #703daa;">delegate</span> = <span style="color: #bb2ca2;">self</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> picker.</span><span style="color: #703daa;">sourceType</span><span style="color: black;"> = </span>UIImagePickerControllerSourceTypeCamera<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>presentViewController<span style="color: black;">:picker </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Add <span style="color: #703daa;">UIImagePickerController's </span>delegate method to handle camera event</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)imagePickerController:(<span style="color: #703daa;">UIImagePickerController</span> *)picker didFinishPickingMediaWithInfo:(<span style="color: #703daa;">NSDictionary</span> *)info {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [picker </span>dismissViewControllerAnimated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #4f8187;">imageView</span><span style="color: black;">.</span><span style="color: #703daa;">image</span><span style="color: black;"> = [info </span><span style="color: #3d1d81;">objectForKey</span><span style="color: black;">:</span>@"UIImagePickerControllerOriginalImage"<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our ViewController.m file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// CameraDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/28/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> imageView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's life cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//Open Camera button click method</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)openCamera:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UIImagePickerController<span style="color: black;"> * picker = [[</span>UIImagePickerController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>picker.<span style="color: #703daa;">delegate</span> = <span style="color: #bb2ca2;">self</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> picker.</span><span style="color: #703daa;">sourceType</span><span style="color: black;"> = </span>UIImagePickerControllerSourceTypeCamera<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//start camera view</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>presentViewController<span style="color: black;">:picker </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UIImagePickerController's delegate method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//this method get called when we click on USE button after capturing image</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)imagePickerController:(<span style="color: #703daa;">UIImagePickerController</span> *)picker didFinishPickingMediaWithInfo:(<span style="color: #703daa;">NSDictionary</span> *)info {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [picker </span>dismissViewControllerAnimated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;"> </span>completion<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//set captured image on our app's ImageView</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #4f8187;">imageView</span><span style="color: black;">.</span><span style="color: #703daa;">image</span><span style="color: black;"> = [info </span><span style="color: #3d1d81;">objectForKey</span><span style="color: black;">:</span>@"UIImagePickerControllerOriginalImage"<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: red;"><i>Note : Make you have to Run application using Apple's Real Device (iPhone, iPod, and iPad etc.), you can't test camera app in simulator.</i></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I clicked on <b>Open Camera Button</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtS35nEBD4Wgc9FIIvCiqssi0bxYe4lEJDT2H0bMyqJ1TbAl4B403VgusaZuLxbBlGt1TSuyJewXGDMPBnN-byPvhOvIWeOHeTexmn-sTyHoovs5yvFsSs63dzn32Hx7JO6aPQut2lYJpY/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtS35nEBD4Wgc9FIIvCiqssi0bxYe4lEJDT2H0bMyqJ1TbAl4B403VgusaZuLxbBlGt1TSuyJewXGDMPBnN-byPvhOvIWeOHeTexmn-sTyHoovs5yvFsSs63dzn32Hx7JO6aPQut2lYJpY/s320/Screen+12.png" width="215" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
then I Captured photo and click on <b>Use Button</b> </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj35BWsWhRmPgNET4Kg0O-JzaoC9mPglBi_BFnvIuGGFaWju62C8AGKK2ADM7rnJzeNoj69i8kW9vey5oVG_n1NV010ZRkTY2dBn3Gbae1GR4rKqJ6wjBKCCnkAzJz8Tj0_oNPbGsfNkipT/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj35BWsWhRmPgNET4Kg0O-JzaoC9mPglBi_BFnvIuGGFaWju62C8AGKK2ADM7rnJzeNoj69i8kW9vey5oVG_n1NV010ZRkTY2dBn3Gbae1GR4rKqJ6wjBKCCnkAzJz8Tj0_oNPbGsfNkipT/s320/Screen+13.png" width="221" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. It was so simple because Apple doing everything for us.</div>
<div style="font-family: Helvetica; font-size: 12px;">
we just made it alive.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <a href="https://www.opendrive.com/files?M181OTMxNzA3X0dwV1Bh" target="_blank"><b><span style="color: #38761d;">CameraDemo</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thought !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-2001188183181195042013-02-27T22:03:00.001-08:002013-03-05T02:49:44.087-08:00Table View in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Today we are going to create very simple application to understand understand How Table View works in iOS.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
While you are writing code for iOS Application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Always keeps in mind below written Five steps while developing iOS application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Create All the Required Files </div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Design UI (Using Interface Builder)</div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Write Objective -C code for functionality (in .h and m files as well)</div>
<div style="font-family: Helvetica; font-size: 12px;">
4. Need to hook-up or UI Items with Objective-C code (Using file owner).</div>
<div style="font-family: Helvetica; font-size: 12px;">
5. Execute the application</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So let's Fire!! Xcode .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Create New Project this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. File --> New --> Project -->Empty Application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. In the Next Window Screen put the Values as </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Product Name: <b>TableViewDemo</b></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Org Name : RDCWorld</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Company Identifier (package name) : com.rdcworld</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave blank for now)</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Devices : select iPhone (if its not selected)</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
then check Tick mark for "Use Automatic Reference Counting" option to enable ARC.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
and click on Finish button.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
3 . After creating initial app, you can see the Default Xcode Dashboard with having Project Structure on Left side.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
we have mainly these files so far.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
AppDelegate.h</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
AppDelegate.m</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
main.m</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
So now we need to Add one UIViewController to show our table View.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
so here we go ..</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
1. Right click on project (Blue Icon) </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
New File -->iOS (Cocoa Touch) --> Objective -C class --> Next</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
In the next window screen you need to put values like this </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Class : MyViewController</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Subclass of : UIViewController</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Make a Tick Mark on "With XIB fo.r user interface" option.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
then go Next.. --> Create.</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
Good!! now you can see Three more new files added to our project</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
MyViewController.h</div>
<div style="font-family: Helvetica; font-size: 12px;">
MyViewController.m</div>
<div style="font-family: Helvetica; font-size: 12px;">
MyViewController.xib</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay we have created all the required files, So far our Project Structure is looking like below snap shot</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuGC9ujBHQsjzSzHBK33o3sljgLcieefqem2diMNL3czhc2KNTljpXwG24U9OSF2FG-4AvDC-1PVn5IQmomgD4MOLxdSQI8M6zqDFSGrfgGrFH4XZu1G8RgIoTVfXms2M7tQXdP_3zid52/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuGC9ujBHQsjzSzHBK33o3sljgLcieefqem2diMNL3czhc2KNTljpXwG24U9OSF2FG-4AvDC-1PVn5IQmomgD4MOLxdSQI8M6zqDFSGrfgGrFH4XZu1G8RgIoTVfXms2M7tQXdP_3zid52/s320/Screen+1.png" width="223" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we need to handle design things if we have any.</div>
<div style="font-family: Helvetica; font-size: 12px;">
In this application we just use UITableView only so its pretty simple.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Just open MyViewController.XIB file.</div>
<div style="font-family: Helvetica; font-size: 12px;">
(You can see blank Layout with white background )</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now look at the UI Library (on Bottom Right Side in XCode)</div>
<div style="font-family: Helvetica; font-size: 12px;">
and Drag the UITableView (its named as "Table View") to our Layout.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can seed default Table View's layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9nUW4UAtuYr_IGza2dIXulv5yKzTGBOUSIRyEbiRx3mLtmr15WzlVdoT8DfrkONTqdDo6ZQNkLF3p0o-yAMpAyxQk_McbGmqzLMxwTRPouoXbjy6VuLxnK6F1aH374HC_eRmFCkl0CU_Y/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9nUW4UAtuYr_IGza2dIXulv5yKzTGBOUSIRyEbiRx3mLtmr15WzlVdoT8DfrkONTqdDo6ZQNkLF3p0o-yAMpAyxQk_McbGmqzLMxwTRPouoXbjy6VuLxnK6F1aH374HC_eRmFCkl0CU_Y/s320/Screen+2.png" width="188" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
It's time to Write some code..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So let's begin for AppDelegate (App's startup point), we need to define which is our Startup Screen (View Controller) on this app.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Okay, Open the AppDelegate.h file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Add <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@class </span>directive just below to <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#import </span>statement</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>MYViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
1.2 then add property for it (below to UIWindow's property)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">MYViewController</span> *myViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Finally our AppDelegate.h file look like this</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TableViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/27/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>MYViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">MYViewController</span> *myViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Now come to the AppDelegate.m file (double click on it to open)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">2.1 add </span><span style="color: #78492a;">#import </span>"MYViewController.h" </div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 now we need to synthesize MyViewController's property what we defined in .h file.</div>
<div style="font-family: Helvetica; font-size: 12px;">
so just add below code after <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.3 in didFinishLaunchingWithOptions method.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
delete below line</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;">.</span>backgroundColor<span style="color: black;"> = [</span>UIColor<span style="color: black;"> </span><span style="color: #3d1d81;">whiteColor</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
and replace with given code lines</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
myViewController<span style="color: black;"> = [[</span>MYViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span>myViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
That's it Save the code now!!</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
So Finally our AppDelegate.m file look like this.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TableViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/27/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"MYViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>myViewController<span style="color: black;"> = [[</span>MYViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span>myViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillResignActive:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationDidEnterBackground:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. </div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillEnterForeground:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationDidBecomeActive:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillTerminate:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
For this time if you will execute application you can See blank table on your screen.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFWPW0pEPhviTiKgELIHmye2SO__mq8YRVzyKL0nZ9V26fktJD34k1t1xfeGWbLNKarPhdQlTfAyEJnd7rAZciKKPVOGFiYDjQq2lAz9Qc8q7Lra2fZWFK04ylEFbulqt2vhdfOoLWBUW6/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFWPW0pEPhviTiKgELIHmye2SO__mq8YRVzyKL0nZ9V26fktJD34k1t1xfeGWbLNKarPhdQlTfAyEJnd7rAZciKKPVOGFiYDjQq2lAz9Qc8q7Lra2fZWFK04ylEFbulqt2vhdfOoLWBUW6/s320/Screen+3.png" width="167" /></a></div>
<div style="font-family: Menlo; font-size: 11px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Now is the main Task.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
We will implement table view's delegate and datasource's methods</div>
<div style="font-family: Menlo; font-size: 11px;">
* to put data on table view</div>
<div style="font-family: Menlo; font-size: 11px;">
* to create table cell,no of rows etc.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Let's make it simple as we can.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
First is First!! open header file (MyViewController.h)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
1. define UITableView's delegate and datasource </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"><</span>UITableViewDelegate<span style="color: black;">,</span>UITableViewDataSource<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. create one <span style="color: #703daa;">NSMutableArray</span> (give name as "myFavMusicList")to store our </div>
<div style="font-family: Menlo; font-size: 11px;">
favorite music list (we will show in table view).</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSMutableArray</span><span style="color: black;"> *myFavMusicList;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
So Make sure Finally we have our MyViewController.h file code like this</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
///</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// MYViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TableViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/27/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> MYViewController : </span>UIViewController<span style="color: black;"><</span>UITableViewDelegate<span style="color: black;">,</span>UITableViewDataSource<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSMutableArray</span><span style="color: black;"> *myFavMusicList;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Come to the Heart of the application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Open Implementation (ViewController.m ) file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. synthesize the favMusicList array after just <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myFavMusicList;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2. in viewDidLoad method </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.1 initialize array </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>myFavMusicList<span style="color: black;"> = [[</span><span style="color: #703daa;">NSMutableArray</span><span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
2.2 then add the values</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Boulevard of broken dreams"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"We Will Rock You"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Stairway To Heaven"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Rang De Basanti"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"We are the champions"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Nothing Else Matters"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Wake Me Up When September Ends"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Crawling in my skin"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Summer of '69"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Temple Of The King"<span style="color: black;">];</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Final code..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
to make table alive, mainly Two method always required</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
numberOfRowsInSection : how many rows in our table</div>
<div style="font-family: Menlo; font-size: 11px;">
cellForRowAtIndexPath : create the table's cell or put the data on rows</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3.1 so add the "numberOfRowsInSection" method code just before <span style="color: #bb2ca2;">@end</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">int</span>) tableView:(<span style="color: #703daa;">UITableView</span> *)tableView numberOfRowsInSection:(<span style="color: #703daa;">NSInteger</span>)section{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> [</span>myFavMusicList<span style="color: black;"> </span><span style="color: #3d1d81;">count</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3.2 now create the cell for every row in our table in "cellForRowAtIndexPath"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">UITableViewCell</span> *) tableView:(<span style="color: #703daa;">UITableView</span> *)tableView cellForRowAtIndexPath:(<span style="color: #703daa;">NSIndexPath</span> *)indexPath{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #703daa;">NSString</span> *cellIdentifier = <span style="color: #d12f1b;">@"tableCell"</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UITableViewCell<span style="color: black;"> *cell;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
cell = [tableView <span style="color: #3d1d81;">dequeueReusableCellWithIdentifier</span>:cellIdentifier]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (cell == <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> cell = [[</span><span style="color: #703daa;">UITableViewCell</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithStyle<span style="color: black;">:</span>UITableViewCellStyleDefault<span style="color: black;"> </span>reuseIdentifier<span style="color: black;">:cellIdentifier];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *musicLabel = [<span style="color: #4f8187;">myFavMusicList</span> <span style="color: #3d1d81;">objectAtIndex</span>:indexPath.<span style="color: #703daa;">row</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
cell.<span style="color: #703daa;">textLabel</span>.<span style="color: #703daa;">text</span> = musicLabel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> cell; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
That's perfect!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our MyViewController.m file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// MYViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TableViewDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/27/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"MYViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>MYViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> MYViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myFavMusicList;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//initilize array</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>myFavMusicList<span style="color: black;"> = [[</span><span style="color: #703daa;">NSMutableArray</span><span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add values</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Boulevard of broken dreams"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"We Will Rock You"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Stairway To Heaven"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Rang De Basanti"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"We are the champions"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Nothing Else Matters"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Wake Me Up When September Ends"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Crawling in my skin"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Summer of '69"<span style="color: black;">];</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">myFavMusicList</span><span style="color: black;"> </span><span style="color: #3d1d81;">addObject</span><span style="color: black;">:</span>@"Temple Of The King"<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - UITableView's Delegate and Datasource methods</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//data source </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">int</span>) tableView:(<span style="color: #703daa;">UITableView</span> *)tableView numberOfRowsInSection:(<span style="color: #703daa;">NSInteger</span>)section{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> [</span>myFavMusicList<span style="color: black;"> </span><span style="color: #3d1d81;">count</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">UITableViewCell</span> *) tableView:(<span style="color: #703daa;">UITableView</span> *)tableView cellForRowAtIndexPath:(<span style="color: #703daa;">NSIndexPath</span> *)indexPath{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">static</span> <span style="color: #703daa;">NSString</span> *cellIdentifier = <span style="color: #d12f1b;">@"tableCell"</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UITableViewCell</span> *cell; </div>
<div style="font-family: Menlo; font-size: 11px;">
cell = [tableView <span style="color: #3d1d81;">dequeueReusableCellWithIdentifier</span>:cellIdentifier]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//we will re-use our cell, while scrolling table</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (cell == <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> cell = [[</span><span style="color: #703daa;">UITableViewCell</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithStyle<span style="color: black;">:</span>UITableViewCellStyleDefault<span style="color: black;"> </span>reuseIdentifier<span style="color: black;">:cellIdentifier]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *musicLabel = [<span style="color: #4f8187;">myFavMusicList</span> <span style="color: #3d1d81;">objectAtIndex</span>:indexPath.<span style="color: #703daa;">row</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
cell.<span style="color: #703daa;">textLabel</span>.<span style="color: #703daa;">text</span> = musicLabel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> cell; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we need to hookup below items to our application's File Owner</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
i . UITableViewDelegate</div>
<div style="font-family: Helvetica; font-size: 12px;">
ii . UITableViewDataSource</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
First we will hook-up UITableView's data source & delegate to its File Owner.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Open MyViewController.xib file</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 Select UITableView on Layout</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.3 Select Connection Inspector in Top Right side (as shown in below picture)</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.4 now click on (+) for data source (its also on Top right side) and drag cursor to File Owner ( Yellow Box on Left side).</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnJSYmQ0hlOCLITg1JGK78RYxCoUNSODH4SYecPmOszgprMzwsAIiFf-R4U5QfCpRKTZoO9maKJc7lob1_-OiTrkdytjvjJhPlQ2o-djYoBOOFAHZ_H8XKbQI2ODC1qgKO35Bn6V3bYaAh/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnJSYmQ0hlOCLITg1JGK78RYxCoUNSODH4SYecPmOszgprMzwsAIiFf-R4U5QfCpRKTZoO9maKJc7lob1_-OiTrkdytjvjJhPlQ2o-djYoBOOFAHZ_H8XKbQI2ODC1qgKO35Bn6V3bYaAh/s320/Screen+4.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now do the same for delegate also. If you on the right way and did it well you can see Connection Inspector property look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirkqy3i_ts1xcnWyxbeUpoA3f74B5ceKn4rAaVTorNesdD-K1fQyuK466IHZC3n7U6jj2Bh-VUH-j5r-WPOjqHsUflzHzQGQ6erK12rJLwc0YOD9NGCfeKQ4dk_V75oI6IH3t_iG8zQFOF/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirkqy3i_ts1xcnWyxbeUpoA3f74B5ceKn4rAaVTorNesdD-K1fQyuK466IHZC3n7U6jj2Bh-VUH-j5r-WPOjqHsUflzHzQGQ6erK12rJLwc0YOD9NGCfeKQ4dk_V75oI6IH3t_iG8zQFOF/s1600/Screen+5.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - V</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
It's time to wrap it up. So let's Save application and Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO3H9efiXEoVeUsL5PkuSmIEkHlTjOgUW9BnhTGJMGaXLhgym_e1cFRsBnhCwdkPgnxvvCQLcDSwFRmjVJR3hz8y5vzTDoeUvpP0JJOzeNW9hr6qlkssIfu-aYIQMhaGBl9-guBzy8GQr0/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO3H9efiXEoVeUsL5PkuSmIEkHlTjOgUW9BnhTGJMGaXLhgym_e1cFRsBnhCwdkPgnxvvCQLcDSwFRmjVJR3hz8y5vzTDoeUvpP0JJOzeNW9hr6qlkssIfu-aYIQMhaGBl9-guBzy8GQr0/s320/Screen+6.png" width="162" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Wooooh!! we did it. Table View is the on of Important part in iOS app development.</div>
<div style="font-family: Helvetica; font-size: 12px;">
We learn it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can download complete application source code zip file here : <a href="https://www.opendrive.com/files?M181OTMxNzEzX0g4Umkw" target="_blank"><b><span style="color: #38761d;">TableViewDemo</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I would love to here your thought!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-34755596708359649542013-02-25T02:44:00.001-08:002013-03-05T02:45:45.039-08:00Delegate in iOS<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Fire Xcode and Create New Project --> Select "Empty Project" in iOS Application (see on left side options). go next</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVVDJ_AhIvmfQLFFGDGAdBkQg_IjzfHSbrkGJKyRZH8-9hOZI1WqlxaRgvWbLh9BtDGfaZXVxehdsqS_4gKnyjFNOIfqfG38jbXMQd4sCq6zbKznYGaWoDbHyVJAWGZ_TD4hG_Pll8n5rU/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="260" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVVDJ_AhIvmfQLFFGDGAdBkQg_IjzfHSbrkGJKyRZH8-9hOZI1WqlxaRgvWbLh9BtDGfaZXVxehdsqS_4gKnyjFNOIfqfG38jbXMQd4sCq6zbKznYGaWoDbHyVJAWGZ_TD4hG_Pll8n5rU/s400/Screen+1.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the next screen put the values like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Product Name: <b>DelegateDemo</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
Org Name : RDCWorld</div>
<div style="font-family: Helvetica; font-size: 12px;">
Company Identifier (package name) : com.rdcworld</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class Prefix : (leave blank for now)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Devices : select iPhone (if its not selected)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
then check Tick mark for "Use Automatic Reference Counting" option to enable ARC.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and click on Finish button.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz3ltRqc7QX5YmVt1z6suLJEEfLJrExNKaTgR6-iDaWZx4sTftd7rSA8P97BHGe-QSni4HYU3oSgzU0-5cioHjE5lrTJmqorPNiNvN8ZlSxSUPghfHXCUG-puE1aEZp4roDLDmBE-eeH2d/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz3ltRqc7QX5YmVt1z6suLJEEfLJrExNKaTgR6-iDaWZx4sTftd7rSA8P97BHGe-QSni4HYU3oSgzU0-5cioHjE5lrTJmqorPNiNvN8ZlSxSUPghfHXCUG-puE1aEZp4roDLDmBE-eeH2d/s400/Screen+2.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In this screen select location to save your project and click on create button.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQjCrA9hx18gy7OFnkg23oSWvyObKMc-s9V8CZumEIpSBYtKAG3-GShyphenhyphenlE3H2ZhacrcqyN5tLXYztMp7vSGrhG77s5RRIFKhhxwXo_2kZYvvmq_MjGTEX8YNJBBTovdJbBogNERv4pH4Ka/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="338" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQjCrA9hx18gy7OFnkg23oSWvyObKMc-s9V8CZumEIpSBYtKAG3-GShyphenhyphenlE3H2ZhacrcqyN5tLXYztMp7vSGrhG77s5RRIFKhhxwXo_2kZYvvmq_MjGTEX8YNJBBTovdJbBogNERv4pH4Ka/s400/Screen+3.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So here is the default Xcode dashboard look like when you create new project.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5z6a4K341xsguBPj-2Vy8TP0tl_FN0esARRMFzOCWngBoSy4Y2cX0W6QvjSK-EpHC3inpuhvhOTh0WYOK8L3KPtIqv6qqKCQA9dvdi74FKIbExYZrKi-3W6osLjrz-Pzbc7h2WF3RqXV0/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5z6a4K341xsguBPj-2Vy8TP0tl_FN0esARRMFzOCWngBoSy4Y2cX0W6QvjSK-EpHC3inpuhvhOTh0WYOK8L3KPtIqv6qqKCQA9dvdi74FKIbExYZrKi-3W6osLjrz-Pzbc7h2WF3RqXV0/s400/Screen+4.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
See we have only two files</div>
<div style="font-family: Helvetica; font-size: 12px;">
AppDelegate.h</div>
<div style="font-family: Helvetica; font-size: 12px;">
AppDelegate.m</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
these are the most important and default file for every application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
so we don''t have any view controller in our project because we selected </div>
<div style="font-family: Helvetica; font-size: 12px;">
"Empty application " option </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For this application We will create two View Controllers for having two screens.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
in FirstViewController (we will send data to SecondViewController using delegate)</div>
<div style="font-family: Helvetica; font-size: 12px;">
in SecondViewController (We will get the data sent by First)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So lets create ViewController.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
First we will create new Group (Folder) for our Controllers </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Right click on Project Icon (Blue Icon) and click on "New Group" as shown in below picture.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxuZLyytRH7axUq_U0GzIoBJKy31UQpO2cglMQ5bkfOYfzS2CALXpGZhXSzLg2b1Wm7qWb4Oemw3PRhR4OsXJZL0idmSnRR3-LBE5aJsM8UoSwYf6fBYdz0Yu81DEiO0e5DGbJ5g3_tfMO/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxuZLyytRH7axUq_U0GzIoBJKy31UQpO2cglMQ5bkfOYfzS2CALXpGZhXSzLg2b1Wm7qWb4Oemw3PRhR4OsXJZL0idmSnRR3-LBE5aJsM8UoSwYf6fBYdz0Yu81DEiO0e5DGbJ5g3_tfMO/s320/Screen+5.png" width="258" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
double click on it and change default name to " Controllers ".</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now it time to create new ViewController</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
so, just right click on newly created Group "Controllers" and click on "New File" option</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-unYNvUBeZHVro0B12yUhwpdXZ2_DmBPe0pG2X-lh6R9NurEEpsdu-7h1vJ7VWyiiIsbtsEtZZ-Whk_hp_ubXpBRJEonKzkT4pgXxYKuaM1Z06SifuOhJitjwa6Vevfy_usno3w7eKFAI/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="296" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-unYNvUBeZHVro0B12yUhwpdXZ2_DmBPe0pG2X-lh6R9NurEEpsdu-7h1vJ7VWyiiIsbtsEtZZ-Whk_hp_ubXpBRJEonKzkT4pgXxYKuaM1Z06SifuOhJitjwa6Vevfy_usno3w7eKFAI/s320/Screen+6.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Select "Objective-C class" in iOS - Cocoa Touch option (on left side) and go Next </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="260" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVYKSNHL-ENrsfXGRBAIHQ-Jxt8I1HQo0PK0eirfnyHKEqYVxNA5_oZI3H60KtT0FRfkmXCkZJLVtqbLQ2POBZqg4TlpTEq2bn6w7OXLaVTH-B08tu1nH6g5kiwlojANbQvTzKWIqpeJia/s400/Screen+7.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
in the next window just put</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class : "FirstViewCotroller" (its the name of our new controller)</div>
<div style="font-family: Helvetica; font-size: 12px;">
Subclass of : UIViewController</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
don't forget to add Tick mark on "With XIB" for user interface</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now go ahead and create..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYGrbMxcImeTJdQrk-9QDO5v3jas818MSuNmW5AdU10pFTXJgiKo_djkdz4wDocFNZf94IG5XSaoZZ28Cg7C9vtuZtSVhwrGx2eFN4E0tffh-LLuAw81so4a5pOqEd5Fvqi1y5HtCSzFiC/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYGrbMxcImeTJdQrk-9QDO5v3jas818MSuNmW5AdU10pFTXJgiKo_djkdz4wDocFNZf94IG5XSaoZZ28Cg7C9vtuZtSVhwrGx2eFN4E0tffh-LLuAw81so4a5pOqEd5Fvqi1y5HtCSzFiC/s400/Screen+8.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see three new files added into our project in Group "Controllers"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
FirstViewController.h</div>
<div style="font-family: Helvetica; font-size: 12px;">
FirstViewController.m</div>
<div style="font-family: Helvetica; font-size: 12px;">
FirstViewController.xib</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Nice!! now we need to add one more controller, Go ahead same way and Create new View Controller</div>
<div style="font-family: Helvetica; font-size: 12px;">
and Give it name as "SecondViewController".</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
If you have done this very well then you can see three more files added in Group "Controllers"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
SecondViewController.h</div>
<div style="font-family: Helvetica; font-size: 12px;">
SecondViewController.m</div>
<div style="font-family: Helvetica; font-size: 12px;">
SecondViewController.xib</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
It's time to write some code…</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, we will start writing code from AppDelegate File, because we need to define which View Controller is startup screen for application. in our app its "First View Controller"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the default code of "AppDelegate.h" file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now add</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
@class FirstViewController;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just after #import statement.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then add property for First View Controller like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">strong</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #4f8187;">FirstViewController</span> *firstViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
So Finally our "AppDelegate.h" file l<span style="font-family: Helvetica; font-size: 12px;">ook like this</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">-----------------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DelegateDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/22/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>FirstViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">strong</span>, <span style="color: #bb2ca2;">nonatomic</span>) <span style="color: #4f8187;">FirstViewController</span> *firstViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
if you did any mistake just make it like this. and go ahead open "AppDelegate.m" file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
in this file, you can see many method with comments, don't worry about all these.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
we will do three task.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add import statement for FirstViewController</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"FirstViewController.h"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. synthesize our FirstViewController's property. Just below to @implementation directive</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> firstViewController;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
3. Now in the "didFinishLaunchingWithOptions"<span style="font-family: Helvetica; font-size: 12px;"> method</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
delete below line</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<strike><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;">.</span>backgroundColor<span style="color: black;"> = [</span>UIColor<span style="color: black;"> </span><span style="color: #3d1d81;">whiteColor</span><span style="color: black;">];</span></strike></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
and replace with this code</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
firstViewController<span style="color: black;"> = [[</span>FirstViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
UINavigationController<span style="color: black;"> *firstView = [[</span>UINavigationController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithRootViewController</span><span style="color: black;">:</span><span style="color: #4f8187;">firstViewController</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;">.</span>rootViewController<span style="color: black;"> = firstView;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
what we doing is , creating FirstViewController's instance and added to Navigation Controller</div>
<div style="font-family: Helvetica; font-size: 12px;">
then at last we added NavigationController as a rootViewController to our UIWindow, so it will be startup screen with FirstView.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
So Finally our "AppDelegate.m" file l<span style="font-family: Helvetica; font-size: 12px;">ook like this</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;"><br /></span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;">-----------------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DelegateDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/22/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"FirstViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> firstViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Override point for customization after application launch.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create instance of FirstViewController</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>firstViewController<span style="color: black;"> = [[</span>FirstViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//create UINavigationController instance using firstViewController</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>UINavigationController<span style="color: black;"> *firstView = [[</span>UINavigationController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithRootViewController</span><span style="color: black;">:</span><span style="color: #4f8187;">firstViewController</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//added navigation controller to window as a rootViewController</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span>.<span style="color: #4f8187;">window</span>.<span style="color: #703daa;">rootViewController</span> = firstView;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillResignActive:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationDidEnterBackground:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. </div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillEnterForeground:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationDidBecomeActive:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)applicationWillTerminate:(<span style="color: #703daa;">UIApplication</span> *)application</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="min-height: 14px;">
<br /></div>
<div style="min-height: 14px;">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So far so good, for now if you will execute application it will show FirstViewController as First Screen With just simple blue navigation bar (on top) and white background.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So it's time to add one TextField and Button on FirstViewController to get input data, and one Label on SecondViewController to show data.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Open FirstViewController.XIB (double click on it, it opens in Interface Builder), you will see blank White Layout.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Add Navigation Bar on it, just click on <b>Attribute Inspector</b> and change the Top Bar value to "Navigation Bar"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNC5Y6b56Il7EH_KFHPU8NXVQxOR2viXS1VrBKJQNKfpAegEiYYqoyO1i-oURqYRRevNe_YFCvZTQSGBj9a4yFgq6CrLSdGxj_S0m4fBWau1m8eCLZw5VPWL8sTyVF_aR6Bg8ZrkWJAqmG/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="177" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNC5Y6b56Il7EH_KFHPU8NXVQxOR2viXS1VrBKJQNKfpAegEiYYqoyO1i-oURqYRRevNe_YFCvZTQSGBj9a4yFgq6CrLSdGxj_S0m4fBWau1m8eCLZw5VPWL8sTyVF_aR6Bg8ZrkWJAqmG/s320/Screen+9.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Drag one TextField and Button on screen, select TextField and click on again <b>Attribute Inspector </b>and </div>
<div style="font-family: Helvetica; font-size: 12px;">
change placeholder value "enter your message" then select Button and give it name "Next" like this..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidi3grJwr_ZjqaLzOUnw1FcSqVgDs2azFV-XGSyTcaBX6c720YC5cNV7raQvghe8DrwTCiDbgKy401BsxdrAA0Rw99jsAn9vUVECS1fDZitGNBK3RwYBkFbrvsBgPNDsAFrB1ddxaz6cKO/s1600/Screen+10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="217" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidi3grJwr_ZjqaLzOUnw1FcSqVgDs2azFV-XGSyTcaBX6c720YC5cNV7raQvghe8DrwTCiDbgKy401BsxdrAA0Rw99jsAn9vUVECS1fDZitGNBK3RwYBkFbrvsBgPNDsAFrB1ddxaz6cKO/s320/Screen+10.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we need to create IBOutlet and IBAction for these items in FirstViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px;">
--But Make sure our FirstViewController.XIB file is selected--</div>
<div style="font-family: Helvetica; font-size: 12px;">
For Creating IBOutlets select <b>Assistant Editor</b> in Editor Toolbar as shown in picture (you can find this on Top Right side in Xcode ).</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see XIB and .h files together like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9JJg6zBEE5AweVFy1cSOX57aZbia0C9K7jotpKdccQVemiew_UH5cb8gRTzNMYfYKOOxMzD6jimszTeC4XV5objVIg-2kQCR_Y2bJTR9OOUns42gIHdU8ILO3Ztt9BM1L3womJvRSkYmL/s1600/Screen+12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9JJg6zBEE5AweVFy1cSOX57aZbia0C9K7jotpKdccQVemiew_UH5cb8gRTzNMYfYKOOxMzD6jimszTeC4XV5objVIg-2kQCR_Y2bJTR9OOUns42gIHdU8ILO3Ztt9BM1L3womJvRSkYmL/s400/Screen+12.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
To create TextField's IBOutlet right click on TextField.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then click on (+) button in "Referencing Outlet" option and drag cursor to its Header file (here its FirstViewController.h) like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjpPAbK7rAUoY93g-_Cz3cNoG6UUNXbz5cAc9yogZ7uGb4pZL67b3dChr9rJnxnL-eH9o3wY4rRu6S0VkqAY-dsiq-Vl8zJ78TDjeCeEaLnK8y1sFNIqBOc850p3WDf1qC4cE2hGawSBeC/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="273" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjpPAbK7rAUoY93g-_Cz3cNoG6UUNXbz5cAc9yogZ7uGb4pZL67b3dChr9rJnxnL-eH9o3wY4rRu6S0VkqAY-dsiq-Vl8zJ78TDjeCeEaLnK8y1sFNIqBOc850p3WDf1qC4cE2hGawSBeC/s400/Screen+13.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now small window will pop up, so put the name for TextField as "textField" and click on <b>connect </b>button</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigM3mUla6AtohBDIm4wKpJeHIi-KDFJ0_SWNmok7_cj3iOcpYfKUc2vVQKJzfPRAeNcQNyco-6MWtjLNoFyM0NE040CI5VXcaOu1CuiingeLWDalXLT20zKOEqu_LkNTJGMac-CcCUpKT9/s1600/Screen+14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="108" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigM3mUla6AtohBDIm4wKpJeHIi-KDFJ0_SWNmok7_cj3iOcpYfKUc2vVQKJzfPRAeNcQNyco-6MWtjLNoFyM0NE040CI5VXcaOu1CuiingeLWDalXLT20zKOEqu_LkNTJGMac-CcCUpKT9/s320/Screen+14.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now same stuff do for creating button's IBOutlet</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOzVnu8kF2G7Y7AFZ9MV54u0DTyqBEgSnlT_jdMQEFy1oKtG-8gxV5EGhHhP0qdjJrzJEK1o_fbHY9uSXLGBT2eYIUHjNgXJsVRhIlRDNFS8UVXrHf_fNlh9vJ1y90l0dB74P-iDFtjcqD/s1600/Screen+15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="281" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOzVnu8kF2G7Y7AFZ9MV54u0DTyqBEgSnlT_jdMQEFy1oKtG-8gxV5EGhHhP0qdjJrzJEK1o_fbHY9uSXLGBT2eYIUHjNgXJsVRhIlRDNFS8UVXrHf_fNlh9vJ1y90l0dB74P-iDFtjcqD/s400/Screen+15.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
put the button name as "nextButton" and click on <b>connect </b>button</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJBoC0X97qdEEJhNmKg_-dub39tbWg3dFpNpeNQ4YKj2Rh_xAEzNbE475vka7FGnvLqq_oQKtD3jx4ZS52xril0uwXwluUfsRnucWhPxTehayBTPgVRR8cnhdxO2iwlEhMg9-h4xRbqPdA/s1600/Screen+16.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="95" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJBoC0X97qdEEJhNmKg_-dub39tbWg3dFpNpeNQ4YKj2Rh_xAEzNbE475vka7FGnvLqq_oQKtD3jx4ZS52xril0uwXwluUfsRnucWhPxTehayBTPgVRR8cnhdxO2iwlEhMg9-h4xRbqPdA/s400/Screen+16.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we will create IBAction (event handler method) for button to handle its Click Event</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Again right click on Next Button, click on (+) button with "Touch Up Inside" option in <b>Send Events</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
and drag cursor to header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg58CQxbvpjNF_zXKlc1G9SkEqHaxIi2R-6AiZF2DTZ7m3kz7ja3PIyx6cwnVhcILd_ln2S0NWqz49-iwaOZcRKdfSvfNHOMB6yVSWg7IffF0ZOoQts2edTKjDUFoHHyM2OYdtwkNVTVuVi/s1600/Screen+17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="293" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg58CQxbvpjNF_zXKlc1G9SkEqHaxIi2R-6AiZF2DTZ7m3kz7ja3PIyx6cwnVhcILd_ln2S0NWqz49-iwaOZcRKdfSvfNHOMB6yVSWg7IffF0ZOoQts2edTKjDUFoHHyM2OYdtwkNVTVuVi/s400/Screen+17.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
give the method name as "buttonPressed"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6hONOK4vNR22y76LrWzDvm9zwshTtQsypng_DnSdnbjNRSI3A57AbDVaOAVmvO3TM4gG2O4mtCQyCxuFnHYbqmgef_qHgxGNW9_FQCmYfdHkbq8-AKL400v_V-eNAeSC-VVZc4-K3O0L-/s1600/Screen+18.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="105" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6hONOK4vNR22y76LrWzDvm9zwshTtQsypng_DnSdnbjNRSI3A57AbDVaOAVmvO3TM4gG2O4mtCQyCxuFnHYbqmgef_qHgxGNW9_FQCmYfdHkbq8-AKL400v_V-eNAeSC-VVZc4-K3O0L-/s400/Screen+18.png" width="400" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cool!! we have created two IBOutlets and One IBAction in our FirstViewController.h file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now click on <b>Standard Editor</b> in Editor ToolBar</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see this code in FirstViewController.h</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *textField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *nextButton;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)buttonPressed:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and empty <b>button Pressed</b> method in FirstViewController.m file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In FirstViewController.h file</div>
<div style="font-family: Helvetica; font-size: 12px;">
add import statement</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"SecondViewController.h"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now add one string for storing input message data in header file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *mesasgeData;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and property also for SecondViewController.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">SecondViewController</span> *secondViewController;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So far make sure our FirstViewController.h file code should be like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>SecondViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> FirstViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *mesasgeData;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *textField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *nextButton;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)buttonPressed:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">SecondViewController</span> *secondViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to the implementation file (FirstViewController.m)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
synthesize the messageData string, textfield and view controller</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> mesasgeData;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> secondViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
then add the code in buttonPressed method.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)buttonPressed:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the input data from text feild and store into string</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>mesasgeData<span style="color: black;"> = </span>textField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//go keypad back when button clicked from textfield</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">textField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//crating instance of second view controller</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondViewController<span style="color: black;"> = [[</span>SecondViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//loading new view via navigation controller</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">secondViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
So far our FirstViewController.m file code look like this (delete any other methods if you have)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"FirstViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>FirstViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> FirstViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> mesasgeData;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> secondViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - View Controller's Life Cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">viewDidLoad</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button Click event handling method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)buttonPressed:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the input data from text feild and store into string</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>mesasgeData<span style="color: black;"> = </span>textField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//go keypad back when button clicked from textfield</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">textField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//crating instance of second view controller</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondViewController<span style="color: black;"> = [[</span>SecondViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//loading new view via navigation controller</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">secondViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Good!! now if you will run the application you can enter message and go to the next screen .</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Come to the second screen.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
First is First, open SecondViewController.XIB file, </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. click on white blank layout, select <b>Attribute Inspector</b> and update the Top Bar value is "Navigation Bar".</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
screen 20</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. We will add two labels to show message, what we got from previous screen.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 double click on First Label and give it value as "We got the message is :'</div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 create IBOutlet for second Label to show message.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For that Select Assistant Editor in Editor ToolBar as we did in last screen.</div>
<div style="font-family: Helvetica; font-size: 12px;">
Right click on Label and create new Referencing outlet this way,</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs7uLNZsrdG_WcZPLM6fzhfQFrE_NMx0Y1bjLEAmvMynDW5KtUA9uCjHe-PlPGCyn-whmGDCzcRratdR4WTqYkV3jQTyTfDXXloxm1iLm7Y0HBJ8ZZEabmYUnqkA3wEmXoZWhSjN82XNDK/s1600/Screen+21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="137" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs7uLNZsrdG_WcZPLM6fzhfQFrE_NMx0Y1bjLEAmvMynDW5KtUA9uCjHe-PlPGCyn-whmGDCzcRratdR4WTqYkV3jQTyTfDXXloxm1iLm7Y0HBJ8ZZEabmYUnqkA3wEmXoZWhSjN82XNDK/s320/Screen+21.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
give the label name as "messageLabel"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAZQZSHzDgG3nnS8vkZr3_2cNduRF-z9BhMFrNEuDMOWKiVfLp-g-8rk6CJtjQ9aEx1XMWgLGCXQSCZqPFqjT7xkowgXeDW3kFfNGjQoyAb-dO7IBKoiKe4cF7Li0fg20owY-ZEn18eLaL/s1600/Screen+22.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="77" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAZQZSHzDgG3nnS8vkZr3_2cNduRF-z9BhMFrNEuDMOWKiVfLp-g-8rk6CJtjQ9aEx1XMWgLGCXQSCZqPFqjT7xkowgXeDW3kFfNGjQoyAb-dO7IBKoiKe4cF7Li0fg20owY-ZEn18eLaL/s320/Screen+22.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
if did this, then come back to Standard Editor in Editor tool bar.</div>
<div style="font-family: Helvetica; font-size: 12px;">
so now you SecondViewController.h file look like this.</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> SecondViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UILabel</span><span style="color: black;"> *messageLabel;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it!! no more UI, IBOutlets,hookup and bla bla bla..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we will write the code to Implement the Delegate Feature in our application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So in SecondViewController.h file </div>
<div style="font-family: Helvetica; font-size: 12px;">
1. First declare delegate with its methods.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@protocol</span> MyDelegate <<span style="color: #703daa;">NSObject</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getMessageString;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. then create our delegate instance to call its methods.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span>id<span style="color: black;"> <</span><span style="color: #4f8187;">MyDelegate</span><span style="color: black;">> myDelegate;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Finally our SecondViewController.h file code is look like this </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SecondViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DelegateDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/22/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//declare our own delegate</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@protocol</span> MyDelegate <<span style="color: #703daa;">NSObject</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getMessageString;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> SecondViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UILabel</span><span style="color: black;"> *messageLabel;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span>id<span style="color: black;"> <</span><span style="color: #4f8187;">MyDelegate</span><span style="color: black;">> myDelegate;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to SecondViewController.m file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. synthesize our messageLabel and delegate variables</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. In <b>viewDidLoad</b> method we need to call delegate's method to get message string and put on message Label (string will be stored by FirstViewController, you will come to know later) .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
messageLabel<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = [</span>myDelegate<span style="color: black;"> </span><span style="color: #31595d;">getMessageString</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
Finally our SecondViewController.m file code is look like this (if any other methods you have just delete those or you can leave, no problem)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// SecondViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DelegateDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/22/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"SecondViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>SecondViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> SecondViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> messageLabel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> myDelegate;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">viewDidLoad</span>]; </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>messageLabel<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = [</span>myDelegate<span style="color: black;"> </span><span style="color: #31595d;">getMessageString</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now at last we need to implement our delegate in FirstViewController to store message string.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Just open the FirstViewController.h file and add delegate this way.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> FirstViewController : <span style="color: #703daa;">UIViewController</span><<span style="color: #4f8187;">MyDelegate</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
So Finally our FirstViewController.h file code is look like this</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// FirstViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DelegateDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/22/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"SecondViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> FirstViewController : <span style="color: #703daa;">UIViewController</span><<span style="color: #4f8187;">MyDelegate</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *mesasgeData;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *textField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *nextButton;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)buttonPressed:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">strong</span>) <span style="color: #4f8187;">SecondViewController</span> *secondViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now come to implementation file (FirstViewController.m)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and implement MyDelegate's <b>getMessageString</b> method this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getMessageString{</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>mesasgeData<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
and most important we need to add one more line in our buttonPressed method while we are going to load next controller.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
secondViewController<span style="color: black;">.</span>myDelegate<span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
So Finally our FirstViewController.m file code is look like this</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// FirstViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// DelegateDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 2/22/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"FirstViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>FirstViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> FirstViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> mesasgeData;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> textField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> secondViewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - View Controller's Life Cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button Click event handling method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)buttonPressed:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the input data from text feild and store into string</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>mesasgeData<span style="color: black;"> = </span>textField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//go keypad back when button clicked from textfield</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">textField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//crating instance of second view controller</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondViewController<span style="color: black;"> = [[</span>SecondViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//it says SecondViewController is implementing MyDelegate</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondViewController<span style="color: black;">.</span>myDelegate<span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//loading new view via navigation controller</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">secondViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span> </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - MyDelegate's method implementation</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getMessageString{</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>mesasgeData<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now save project (command+s) and we all set for execute our application!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output screen (enter any message and press next button)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtc2Zp6kXtaejy5fdHR6bI_uusxE7Xlw6dh9jWxDwWFRFrmwGXV5wHMenpfomUWY-Ery4En-mTipQ_K4Ij3Zv_bj7U0-JBSyh2AB6SfMed6KtUI7UNalmMNVwoX8UmLHjykI5NGv9w0Cst/s1600/Screen+23.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtc2Zp6kXtaejy5fdHR6bI_uusxE7Xlw6dh9jWxDwWFRFrmwGXV5wHMenpfomUWY-Ery4En-mTipQ_K4Ij3Zv_bj7U0-JBSyh2AB6SfMed6KtUI7UNalmMNVwoX8UmLHjykI5NGv9w0Cst/s320/Screen+23.png" width="213" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Wow!! we got the message from previous screen</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0XpXz3u_QfO-2M1e1tlDhpRw_a4eNmRQrGnMeaGxt2QvLxDJ6wPgDKzF5_d6kFi46Pjee9UL4kcxok_K__Vsw646IEcv4i0XA2YIrFlEBhgFp97w9clzI3WSv-416qDAXmRw28KsdOzbR/s1600/Screen+24.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0XpXz3u_QfO-2M1e1tlDhpRw_a4eNmRQrGnMeaGxt2QvLxDJ6wPgDKzF5_d6kFi46Pjee9UL4kcxok_K__Vsw646IEcv4i0XA2YIrFlEBhgFp97w9clzI3WSv-416qDAXmRw28KsdOzbR/s320/Screen+24.png" width="213" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! we learnt one of the important feature of iOS.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You may like to download complete project source code zip file here : <a href="https://www.opendrive.com/files?M181OTMxNzA1X1NZdWRr" target="_blank"><b><span style="color: #38761d;">Delegate Demo in iOS</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I would love to hear feedback :)</div>
</div>
<br /></div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com3Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-53693898853434374902013-02-02T07:24:00.000-08:002013-03-08T07:28:49.483-08:00How to use PList files in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>wake me up when september ends</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Verdana; font-size: 13px;">
here comes the rain again</div>
<div style="font-family: Verdana; font-size: 13px;">
falling from the stars</div>
<div style="font-family: Verdana; font-size: 13px;">
drenched in my pain again</div>
<div style="font-family: Verdana; font-size: 13px;">
becoming who we are.. wake me up when.. </div>
<div style="font-family: Verdana; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
What's up guys, today we are going to learn one more simple but important concept in iPhone application development.. PLists.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So what is the Plist file?</div>
<div style="font-family: Helvetica; font-size: 12px;">
A <b>property list file</b> is an XML file.The file itself is typically encoded using the Unicode UTF-8 encoding and the contents are structured using XML.Storing data on the iPhone or iPad is fairly simple using plist in Key-Value pairs.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLekEo6HyjqJvlAQcQ8QylOi8HRq6S7Ndcmtr8mozZAGJQwHXPLogmjriGZPJKJLy5tGNKYi9VnYyQVVR_M8UXqjBD-CtbZOptUoxETCmyVso9iwpSY4dszdPy1Oa17Xx1GgQ-0lP8HVva/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLekEo6HyjqJvlAQcQ8QylOi8HRq6S7Ndcmtr8mozZAGJQwHXPLogmjriGZPJKJLy5tGNKYi9VnYyQVVR_M8UXqjBD-CtbZOptUoxETCmyVso9iwpSY4dszdPy1Oa17Xx1GgQ-0lP8HVva/s320/Screen+0.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #7b219f; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Before starting You may like to know our plist details</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span style="color: #008400;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Plist file Name : </span>Contacts.plist |</div>
<div style="font-family: Menlo; font-size: 11px;">
|<span style="color: #008400;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Plist Keys Name : </span>Name, Address, PhoneNo |</div>
<div style="font-family: Menlo; font-size: 11px;">
-----------------------------------------------</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6 , Xcode 4.6, and MAC OS X Lion 10.8.1</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
---------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>PListDemo<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span> |</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span> </b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcqltW6Sf_fe4_GmK1C-LtRkaT5pzznLU9jv76PSeHIyY0pANjKruWCdNtgsXJb8Pp7e3jx6kFM7DlK9ezrxfu9kR7ZO0UAsez6SmYZ-n3Gku8lYVgJCPO-rhGBobptdq0pKhEe4RwNDwV/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcqltW6Sf_fe4_GmK1C-LtRkaT5pzznLU9jv76PSeHIyY0pANjKruWCdNtgsXJb8Pp7e3jx6kFM7DlK9ezrxfu9kR7ZO0UAsez6SmYZ-n3Gku8lYVgJCPO-rhGBobptdq0pKhEe4RwNDwV/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px;">
our project structure is look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEJWn7c02t9pxV3bdmx4nr4YW39eSDRiQ-W7zyO6qGxiWDEmQwb0M1D_BByOIUwCGXWqgjuo6WBQLe5cDFS1vvwBKZMNKS79p2H7V7y3NuY23zc6ifPzjHnpzaotJrJ7XwQtSU6z8iitU2/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEJWn7c02t9pxV3bdmx4nr4YW39eSDRiQ-W7zyO6qGxiWDEmQwb0M1D_BByOIUwCGXWqgjuo6WBQLe5cDFS1vvwBKZMNKS79p2H7V7y3NuY23zc6ifPzjHnpzaotJrJ7XwQtSU6z8iitU2/s320/Screen+3.png" width="222" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add some UITextFields, UIButtons on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. TextFields : </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1.1 now drag TextFields for <b>Name</b> ,adjust full width, then go to <b>Attribute <span class="Apple-tab-span" style="white-space: pre;"> </span>Inspector </b>and update Placeholder value as "enter name here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1.2 do same for next TextField for <b>Address</b> and change its Placeholder value as <span class="Apple-tab-span" style="white-space: pre;"> </span>"enter <span class="Apple-tab-span" style="white-space: pre;"> </span>address here" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1.3. drag one more TextField for <b>Phone No</b> and change its Placeholder value as <span class="Apple-tab-span" style="white-space: pre;"> </span>"enter 10 digit phone no" </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. UIButtons: drag 4 Buttons and double click and give them name as <b>Save in Plist</b>, and <b>Get Data from Plist</b> respectively .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now adjust all these items on your Layout as per shown in below screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8StsRMbA8RtsDMUfFBalIdLZmogjwfE17-7pIpJQXy3AWI_tlcighibWFYm6-jEx88abdBeTixHc3gJBLwIQaP-xQfoT0-U0yQq9j7cEioVIy-2PR4Doio5dy_b13ufTcLefYtuMcZSF0/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8StsRMbA8RtsDMUfFBalIdLZmogjwfE17-7pIpJQXy3AWI_tlcighibWFYm6-jEx88abdBeTixHc3gJBLwIQaP-xQfoT0-U0yQq9j7cEioVIy-2PR4Doio5dy_b13ufTcLefYtuMcZSF0/s320/Screen+4.png" width="222" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlets and IBAction )</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UITextFields and IBAction methods for UIButtons .</div>
<div style="font-family: Helvetica; font-size: 12px;">
So just open ViewController.xib </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ETn8RjLBY3rq9P4CJI11xDcwFzMSaVPxMUqB4-FTKc0MMmcu_hC1VnwCVq4tE_Sc_35qUXY98mZ-mYKoI6hjeCQFqxB-108C45Vvl_HOtVAtcAVC_7v3HSLrTH8mqs0lyfnJaxSVOGVT/s1600/Screen+5.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Create IBOutlets</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Select UITextField (which says - 'enter name here') --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 Click on "New Referencing outlet" option and drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end </span><span style="font-family: Menlo; font-size: 11px;">you can see like this.</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCUFNXqysf1vR2oMevOQG4Lk0qoy8RkyMqFKkRiFElVnqovYbIDohRc6365iclLAhakQOCnqHD3zcmGZPna7qIRPXDEbNjAzZoqoxFtWBh_pYzZcvRzBrk3yodIjYgiAvb60DKGY1w1bOb/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="156" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCUFNXqysf1vR2oMevOQG4Lk0qoy8RkyMqFKkRiFElVnqovYbIDohRc6365iclLAhakQOCnqHD3zcmGZPna7qIRPXDEbNjAzZoqoxFtWBh_pYzZcvRzBrk3yodIjYgiAvb60DKGY1w1bOb/s320/Screen+6.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.3 Now you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">nameTextField</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ0bc7BEixmHEWGC0WU929rnfilsuecetvJNUzEvRbVyEpJ_jtxCjxLvIrMzce66eHfonZXRBjaIBvjUa27oi5IBS0IXIEh5d-Ig71tANfTe2ds1AK2lSkorH7GMEQ81Bbp65wwVgf5sTY/s1600/Screen+13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="99" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ0bc7BEixmHEWGC0WU929rnfilsuecetvJNUzEvRbVyEpJ_jtxCjxLvIrMzce66eHfonZXRBjaIBvjUa27oi5IBS0IXIEh5d-Ig71tANfTe2ds1AK2lSkorH7GMEQ81Bbp65wwVgf5sTY/s320/Screen+13.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see below line added in our ViewController's header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *nameTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">1.4 </span>do the same for next two TextFields and give them name as<span style="font-family: Menlo; font-size: 11px;"> "addressTextField" </span>and<span style="font-family: Menlo; font-size: 11px;"> "phoneTextField" </span>respectively<span style="font-family: Menlo; font-size: 11px;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time you can see two IBOutlets created in header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *addressTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *phoneTextField;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Create IBAction methods</div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 Select UIButton (which says -'Save in Plist') --> Right Click on it </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNHWYOd8CE7QYSqFIpadFG5GZ7vETZ5LFpG_ZWRhJxx58-nJpzBkUUOl6bDufQoXS_wZPKKkca7tYP8Mi73zsp3w-KdEfg9gLF8QCl41M3nNPhCoUskIHUSP8_V5_d9Vc73wEimRv2XOLG/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="143" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNHWYOd8CE7QYSqFIpadFG5GZ7vETZ5LFpG_ZWRhJxx58-nJpzBkUUOl6bDufQoXS_wZPKKkca7tYP8Mi73zsp3w-KdEfg9gLF8QCl41M3nNPhCoUskIHUSP8_V5_d9Vc73wEimRv2XOLG/s320/Screen+8.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 Click on <span style="color: #4f7a28;"><b>Touchup Inside</b></span> in "Sent Events" option and drag cursor just below to new created IBOutlets, and put the method name "<span style="font-family: Menlo; font-size: 11px;">saveDataInPlist</span>" in pop window</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLKzExZPh86uoEwdejC-pHlB9j2MExa8uEX0txqhhwF-9ISikTz4NuJKriITcEaA6x4WtlMPCMgJg-uh1n4gRkkym4-KxpoDI9A4c09jQf_3AStCO-spVV9qmweFnpBP_iYpbdKl2a4MSN/s1600/Screen+9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLKzExZPh86uoEwdejC-pHlB9j2MExa8uEX0txqhhwF-9ISikTz4NuJKriITcEaA6x4WtlMPCMgJg-uh1n4gRkkym4-KxpoDI9A4c09jQf_3AStCO-spVV9qmweFnpBP_iYpbdKl2a4MSN/s1600/Screen+9.png" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see new method is added in our ViewController's header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveDataInPlist:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Menlo; font-size: 11px;">2.3 </span>do the same for other Button and give methods name as<span style="font-family: Menlo; font-size: 11px;"> "getDataFromPlist".</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
this time you can see one more new IBAction method created in header file</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getDataFromPlist:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Screen 10</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - iV (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We have added some IBOutlets and IBActions into our header file</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// PListDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 9/2/12.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *nameTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *addressTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *phoneTextField;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveDataInPlist:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getDataFromPlist:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add synthesize (for all declared variable in header file with <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@property</span><span style="font-family: Menlo; font-size: 11px;">)</span> just below to <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@implementation</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> addressTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> phoneTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. update the body of <span style="font-family: Menlo; font-size: 11px;"><b>saveDataInPlist</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveDataInPlist:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the plist document path</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSArray</span><span style="color: black;"> *paths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *documentsDirectory = [paths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSFileManager<span style="color: black;"> *fileManager = [</span>NSFileManager<span style="color: black;"> </span><span style="color: #3d1d81;">defaultManager</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableDictionary<span style="color: black;"> *data = [[</span>NSMutableDictionary<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableArray<span style="color: black;"> *contentArray= [[</span>NSMutableArray<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (![fileManager <span style="color: #3d1d81;">fileExistsAtPath</span>: plistFilePath])</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"File does not exist"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// If the file doesn’t exist, create an empty plist file </div>
<div style="font-family: Menlo; font-size: 11px;">
plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>];</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//NSLog(@"path is %@",plistFilePath);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"File exists, Get data if anything stored"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
contentArray = [[<span style="color: #703daa;">NSMutableArray</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithContentsOfFile</span>:plistFilePath]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">phoneTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//check all the textfields have values</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>) && ([address <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> )&& ([phone <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>)) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add values to dictionary</div>
<div style="font-family: Menlo; font-size: 11px;">
[data <span style="color: #3d1d81;">setValue</span>:name <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"Name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[data <span style="color: #3d1d81;">setValue</span>:address <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"Address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[data <span style="color: #3d1d81;">setValue</span>:phone <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"PhoneNo"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add dictionary to array</div>
<div style="font-family: Menlo; font-size: 11px;">
[contentArray <span style="color: #3d1d81;">addObject</span>:data];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//write array to plist file</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span>([contentArray <span style="color: #3d1d81;">writeToFile</span>:plistFilePath <span style="color: #3d1d81;">atomically</span>:<span style="color: #bb2ca2;">YES</span>]){</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"saved"</span>);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span> = <span style="color: #d12f1b;">@""</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span> =<span style="color: #d12f1b;">@""</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">phoneTextField</span>.<span style="color: #703daa;">text</span> =<span style="color: #d12f1b;">@""</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Saved in plist"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span> {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Couldn't saved"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Couldn't Saved in plist"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Please! enter values"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let me explain what we doing in this method.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.1 First of all we get the Document folder path of our application.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For my case I can see this plist file at below path</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<b>/Users/RDCMac/Library/Application Support/iPhone Simulator/6.1/Applications/37234831-EE6A-41FB-9DDE-FE9BDAE6E53C/Documents/Contacts.plist</b></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #e32400;"><i>Note</i></span><i> : you need to enable hidden files on your MAC system to see this file</i></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.2 then we checked file is exited or not at this path</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.3 if file is already there,read the data into content array if any, else create new empty plist file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.4 we read the text from TextFiles and added to Dictionary using Keys</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.5 and added result dictionary to content array </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2.6 finally we are writing content array to the plist file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. now update the body of <span style="font-family: Menlo; font-size: 11px;"><b>getDataFromPlist</b> </span>method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getDataFromPlist:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the plist document path</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSArray</span><span style="color: black;"> *paths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *documentsDirectory = [paths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSFileManager<span style="color: black;"> *fileManager = [</span>NSFileManager<span style="color: black;"> </span><span style="color: #3d1d81;">defaultManager</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableDictionary<span style="color: black;"> *data = [[</span>NSMutableDictionary<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableArray<span style="color: black;"> *contentArray= [[</span>NSMutableArray<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (![fileManager <span style="color: #3d1d81;">fileExistsAtPath</span>: plistFilePath])</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"file does not exist"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// If the file doesn’t exist, create an empty plist file</div>
<div style="font-family: Menlo; font-size: 11px;">
plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"File exists, Get data if anything stored"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
contentArray = [[<span style="color: #703daa;">NSMutableArray</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithContentsOfFile</span>:plistFilePath];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"contant array is %@"</span>,contentArray);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//print the plist result data on console</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span> (<span style="color: #bb2ca2;">int</span> i= <span style="color: #272ad8;">0</span>; i<[contentArray <span style="color: #3d1d81;">count</span>]; i++) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
data= [contentArray <span style="color: #3d1d81;">objectAtIndex</span>:i];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [data <span style="color: #3d1d81;">objectForKey</span>:<span style="color: #d12f1b;">@"Name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [data <span style="color: #3d1d81;">objectForKey</span>:<span style="color: #d12f1b;">@"Address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [data <span style="color: #3d1d81;">objectForKey</span>:<span style="color: #d12f1b;">@"PhoneNo"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Data From Plist: Name = %@, Address=%@, Phone=%@"<span style="color: black;">,name,address,phone);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// PListDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 9/2/12.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> nameTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> addressTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> phoneTextField;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's life cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Create Plist and store data method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)saveDataInPlist:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the plist document path</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSArray</span><span style="color: black;"> *paths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *documentsDirectory = [paths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSFileManager<span style="color: black;"> *fileManager = [</span>NSFileManager<span style="color: black;"> </span><span style="color: #3d1d81;">defaultManager</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableDictionary<span style="color: black;"> *data = [[</span>NSMutableDictionary<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableArray<span style="color: black;"> *contentArray= [[</span>NSMutableArray<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (![fileManager <span style="color: #3d1d81;">fileExistsAtPath</span>: plistFilePath])</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"File does not exist"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// If the file doesn’t exist, create an empty plist file </div>
<div style="font-family: Menlo; font-size: 11px;">
plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>];</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//NSLog(@"path is %@",plistFilePath);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"File exists, Get data if anything stored"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
contentArray = [[<span style="color: #703daa;">NSMutableArray</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithContentsOfFile</span>:plistFilePath]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = <span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = <span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = <span style="color: #4f8187;">phoneTextField</span>.<span style="color: #703daa;">text</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//check all the textfields have values</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (([name <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>) && ([address <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span> )&& ([phone <span style="color: #3d1d81;">length</span>] ><span style="color: #272ad8;">1</span>)) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add values to dictionary</div>
<div style="font-family: Menlo; font-size: 11px;">
[data <span style="color: #3d1d81;">setValue</span>:name <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"Name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[data <span style="color: #3d1d81;">setValue</span>:address <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"Address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[data <span style="color: #3d1d81;">setValue</span>:phone <span style="color: #3d1d81;">forKey</span>:<span style="color: #d12f1b;">@"PhoneNo"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add dictionary to array</div>
<div style="font-family: Menlo; font-size: 11px;">
[contentArray <span style="color: #3d1d81;">addObject</span>:data];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//write array to plist file</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span>([contentArray <span style="color: #3d1d81;">writeToFile</span>:plistFilePath <span style="color: #3d1d81;">atomically</span>:<span style="color: #bb2ca2;">YES</span>]){</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"saved"</span>);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">nameTextField</span>.<span style="color: #703daa;">text</span> = <span style="color: #d12f1b;">@""</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">addressTextField</span>.<span style="color: #703daa;">text</span> =<span style="color: #d12f1b;">@""</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">phoneTextField</span>.<span style="color: #703daa;">text</span> =<span style="color: #d12f1b;">@""</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Saved in plist"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span> {</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Couldn't saved"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Couldn't Saved in plist"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Please! enter values"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - get data from plist method</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)getDataFromPlist:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//get the plist document path</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSArray</span><span style="color: black;"> *paths = </span>NSSearchPathForDirectoriesInDomains<span style="color: black;">(</span>NSDocumentDirectory<span style="color: black;">, </span>NSUserDomainMask<span style="color: black;">, </span><span style="color: #bb2ca2;">YES</span><span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *documentsDirectory = [paths <span style="color: #3d1d81;">objectAtIndex</span>:<span style="color: #272ad8;">0</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSFileManager<span style="color: black;"> *fileManager = [</span>NSFileManager<span style="color: black;"> </span><span style="color: #3d1d81;">defaultManager</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableDictionary<span style="color: black;"> *data = [[</span>NSMutableDictionary<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>NSMutableArray<span style="color: black;"> *contentArray= [[</span>NSMutableArray<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">]</span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (![fileManager <span style="color: #3d1d81;">fileExistsAtPath</span>: plistFilePath])</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"file does not exist"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// If the file doesn’t exist, create an empty plist file</div>
<div style="font-family: Menlo; font-size: 11px;">
plistFilePath = [documentsDirectory <span style="color: #3d1d81;">stringByAppendingPathComponent</span>:<span style="color: #d12f1b;">@"Contacts.plist"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"File exists, Get data if anything stored"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
contentArray = [[<span style="color: #703daa;">NSMutableArray</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithContentsOfFile</span>:plistFilePath];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"contant array is %@"</span>,contentArray);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//print the plist result data on console</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">for</span> (<span style="color: #bb2ca2;">int</span> i= <span style="color: #272ad8;">0</span>; i<[contentArray <span style="color: #3d1d81;">count</span>]; i++) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
data= [contentArray <span style="color: #3d1d81;">objectAtIndex</span>:i];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *name = [data <span style="color: #3d1d81;">objectForKey</span>:<span style="color: #d12f1b;">@"Name"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address = [data <span style="color: #3d1d81;">objectForKey</span>:<span style="color: #d12f1b;">@"Address"</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *phone = [data <span style="color: #3d1d81;">objectForKey</span>:<span style="color: #d12f1b;">@"PhoneNo"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Data From Plist: Name = %@, Address=%@, Phone=%@"<span style="color: black;">,name,address,phone);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// PListDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 9/2/12.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
<span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@end</span>-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// PListDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 9/2/12.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDCWorld. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here is the output I entered contact details and saved into plist file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwZsgiRTcwA3ob8q1THcOkyqHGIrqSDIB7-XGrHOSqEARVxAc7uTrnCNn0yDABtOxhsX1NRbl5jAL0vEaq1jS0IoveVMZFAKO1kBO33aa0NuelW5FbtrpXLeEqS6g-ygakkcQnr00xK-Ou/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwZsgiRTcwA3ob8q1THcOkyqHGIrqSDIB7-XGrHOSqEARVxAc7uTrnCNn0yDABtOxhsX1NRbl5jAL0vEaq1jS0IoveVMZFAKO1kBO33aa0NuelW5FbtrpXLeEqS6g-ygakkcQnr00xK-Ou/s320/Screen+11.png" width="213" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <a href="https://www.opendrive.com/files?M182MDkwMTg3X3VMVVdW" target="_blank"><b><span style="color: #38761d;">PListDemo.zip (75.81 KB)</span></b></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
<div>
<br /></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-44828704522361399692013-02-02T00:41:00.000-08:002013-04-03T00:41:46.188-07:00Swipe, Pinch, Tap, LongPress and Rotations Gestures Recognition in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
<b>Hola,, iDevelopers,, </b><span style="color: #4f7a28;"><b>RDC</b></span><b> is here</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="color: #d95000; font-family: Helvetica; font-size: 12px;">
in this lovely morning I am enjoying beautiful spanish music on Guitar (with love I called it Mojo)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="font-family: Verdana; font-size: 13px;">So, </span>What's up <span style="color: #0061ff;">guys</span>, today we are going to learn one more simple but important concept in iPhone application development.. Gesture Recognition.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b style="color: #7b219f;"><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So what is the Gesture Recognition?</div>
<div style="font-family: Helvetica; font-size: 12px;">
Let's come with me on Live Concert of our Weekend Show, When you get the beautiful lady (we call Soni Kudi in Punjabi) in front of you.. anyone can see Gesture on your face :)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB5F79RJkql6tDN3lCvfLJ7VkAe7hCL3-nO1-THWlVwNMAkeca9SmlE3sEosUeto0vkIwCT9G9J3c79Y5edLTCFGSg8GBZ3NTDDlSzcWNU7DkG6N6ZueaC_yqMvXSB3_TAze17MOqjt4gn/s1600/surprised.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB5F79RJkql6tDN3lCvfLJ7VkAe7hCL3-nO1-THWlVwNMAkeca9SmlE3sEosUeto0vkIwCT9G9J3c79Y5edLTCFGSg8GBZ3NTDDlSzcWNU7DkG6N6ZueaC_yqMvXSB3_TAze17MOqjt4gn/s320/surprised.jpg" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay no more PJ in morning time.. let's move to our 0101010</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Just stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #7b219f; font-family: Helvetica; font-size: 12px;">
<b style="color: #e32400;">Note : This Application Developed Using : iOS 6.1 , Xcode 4.6, and MAC OS X Lion 10.8.3</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Screen 1</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
---------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>GestureDemo<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0rGupNn35idZ5magEij9TWy1V3dDNke77sPsUBURE0xQthqjpzt5CV2mU5Mpll3yhHyMFkSNbeEronBuppncmi-D0I4o7zvPxeExILT9XCQ6U_ZauI3kMkQMfAWCVuWVag8jHP00ukYw3/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0rGupNn35idZ5magEij9TWy1V3dDNke77sPsUBURE0xQthqjpzt5CV2mU5Mpll3yhHyMFkSNbeEronBuppncmi-D0I4o7zvPxeExILT9XCQ6U_ZauI3kMkQMfAWCVuWVag8jHP00ukYw3/s320/Screen+2.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add some UITextFields, UIButtons on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Let's drag UINavigationBar from Object library double click on it and give title as "Gesture Recogniser Demo", (we will use this for just showing app Title)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select main view and change background to Green Because <b>Green</b> is New <span style="color: #4f7a28;"><b>Black</b></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Drag one UILabel from Object Lib and update its text = <i>Touch Me!! and I'll Recognise That :)</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it simplest UI ever..see below screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKQ7TWpkhIO5Bx4W_MLlGyJgnGuI30pTv4F2LFFGfyb9LnyjTGqsxOQiP4aXErvUV2QfY0Zax8yyJNv7WQ_Vi6whyphenhyphen92zdeBZ1M1kOGk4IyL68qPGXXucyOyiWypLtxkTu3ja_bM8jaT_UL/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKQ7TWpkhIO5Bx4W_MLlGyJgnGuI30pTv4F2LFFGfyb9LnyjTGqsxOQiP4aXErvUV2QfY0Zax8yyJNv7WQ_Vi6whyphenhyphen92zdeBZ1M1kOGk4IyL68qPGXXucyOyiWypLtxkTu3ja_bM8jaT_UL/s320/Screen+3.png" width="221" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Even we don't need any IBOutlet and IBAction in this application :p</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
No change in header file just he default code only.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// GestureDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 02/04/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Here is the Heart of Application</b></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Below are step simple steps To add Gesture in our app</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example: Swipe Gesture</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Create instance of Gesture Recognition class and Initialise with the Selector method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UISwipeGestureRecognizer</span> *swipeGesture = [[<span style="color: #703daa;">UISwipeGestureRecognizer</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTarget</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">action</span>:<span style="color: #bb2ca2;">@selector</span>(swipeGetstureDetected)];</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Explain: Here we have Created swipe gesture instance and initialise it with selector named "<span style="font-family: Menlo; font-size: 11px;">swipeGetstureDetected</span>", So when we swipe on screen this method gets called.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. add Gesture instance to UI. here we are adding on Main Background screen (UIController Screen)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;">[</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">view</span><span style="color: black;"> </span>addGestureRecognizer<span style="color: black;">:swipeGesture];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. now we need to Create the method <span style="font-family: Menlo; font-size: 11px;"><b>swipeGetstureDetected</b> </span>and add desired action in its body.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) swipeGetstureDetected{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Swipe Gesture detected!!"<span style="color: black;">);</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Swipe Gesture detected!!!!"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Helvetica; font-size: 12px;">
//So in this application I have created all the Gesture in a Method and finally I call it from viewDidLoad</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// GestureDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 02/04/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's Life Cycle methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//add GestureReconizers</div>
<div style="color: #31595d; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>addGestureReconizers<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Create and Add GestureReconizers</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) addGestureReconizers{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//1. Swipe</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UISwipeGestureRecognizer</span> *swipeGesture = [[<span style="color: #703daa;">UISwipeGestureRecognizer</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTarget</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">action</span>:<span style="color: #bb2ca2;">@selector</span>(swipeGetstureDetected)]; </div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span>.<span style="color: #703daa;">view</span> <span style="color: #3d1d81;">addGestureRecognizer</span>:swipeGesture];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//2. Pinch</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIPinchGestureRecognizer</span> *pinchGesture = [[<span style="color: #703daa;">UIPinchGestureRecognizer</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTarget</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">action</span>:<span style="color: #bb2ca2;">@selector</span>(pinchGetstureDetected)];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span>.<span style="color: #703daa;">view</span> <span style="color: #3d1d81;">addGestureRecognizer</span>:pinchGesture];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//3. Tap</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UITapGestureRecognizer</span> *tapGesture = [[<span style="color: #703daa;">UITapGestureRecognizer</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTarget</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">action</span>:<span style="color: #bb2ca2;">@selector</span>(TapGestureDetected)];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span>.<span style="color: #703daa;">view</span> <span style="color: #3d1d81;">addGestureRecognizer</span>:tapGesture];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//4. Long Press</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UILongPressGestureRecognizer</span> *longPressGesture = [[<span style="color: #703daa;">UILongPressGestureRecognizer</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTarget</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">action</span>:<span style="color: #bb2ca2;">@selector</span>(longPressGestureDetected)];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span>.<span style="color: #703daa;">view</span> <span style="color: #3d1d81;">addGestureRecognizer</span>:longPressGesture];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//5. Screen Rotation</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIRotationGestureRecognizer</span> *rotationGesture = [[<span style="color: #703daa;">UIRotationGestureRecognizer</span> <span style="color: #3d1d81;">alloc</span>] <span style="color: #3d1d81;">initWithTarget</span>:<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">action</span>:<span style="color: #bb2ca2;">@selector</span>(rotationGestureDetected)];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span>.<span style="color: #703daa;">view</span> <span style="color: #3d1d81;">addGestureRecognizer</span>:rotationGesture];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//6. Drag Item (like swipe)</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>/*UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureDetected)];</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
[self.view addGestureRecognizer:panGesture]; */</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Selectors for Added GestureReconizers</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) swipeGetstureDetected{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Swipe Gesture detected!!"<span style="color: black;">);</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Swipe Gesture detected!!!!"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) pinchGetstureDetected{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Pinch Gesture Detected!!"<span style="color: black;">);</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Pinch Gesture Detected!!"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) TapGestureDetected{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Tap Gesture detected!!"<span style="color: black;">);</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Tap Gesture detected!!"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) longPressGestureDetected{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Long Press Gesture detected!!"<span style="color: black;">);</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Long Press Gesture detected!!"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) rotationGestureDetected{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Rotation Gesture detected!!"<span style="color: black;">);</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Rotation Gesture detected!!"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Ok"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
/*</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
-(void) panGestureDetected{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
NSLog(@"Pan Gesture detected!!");</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Pan Gesture detected!!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
[alert show];</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
*/</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// GestureDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 02/04/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// GestureDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 02/04/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #9929bd;">I pinched on Screen</span> and here is the Result screen</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKrGRCZ1auOnXtO95IqtuEXM43kfnmXsg5t89u6edMtXbZArSWuAO0xSIU0asLqNBrgub8ZSsEl8OjwSlTOodYtiBwzbsPgIcg6Sfj5LQKnhCfLUzNhwZpBFivnzIOKxUqZW3F-r2w-cm_/s1600/Screen+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKrGRCZ1auOnXtO95IqtuEXM43kfnmXsg5t89u6edMtXbZArSWuAO0xSIU0asLqNBrgub8ZSsEl8OjwSlTOodYtiBwzbsPgIcg6Sfj5LQKnhCfLUzNhwZpBFivnzIOKxUqZW3F-r2w-cm_/s320/Screen+4.png" width="222" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
This time <span style="color: #d95000;">I swipe</span>, and see what it says..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnrVih95hiz3IFLGuhK6hV1YrDegHBQdVb72g5zOeHtM1_cBv6ZkvyzATIVtm0X9i3hYaSkDEKSDS_ymZma5Sxxj8d0K1mP_hrVZODnjUrPdfrI_NG_hd8An26nv0pGo7tmkEZgKjjRhm7/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnrVih95hiz3IFLGuhK6hV1YrDegHBQdVb72g5zOeHtM1_cBv6ZkvyzATIVtm0X9i3hYaSkDEKSDS_ymZma5Sxxj8d0K1mP_hrVZODnjUrPdfrI_NG_hd8An26nv0pGo7tmkEZgKjjRhm7/s320/Screen+5.png" width="220" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #0042aa; font-family: Helvetica; font-size: 12px;">
<span style="color: black;">Now </span>let's Tap (Touch) <span style="color: black;">on screen</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq5sQPPpj8Lt7nq1Cho4N340buTnxQNisRaJUBAaYjdn8DOK7PlCAxtsndu2R7RAkgjJH6jdtAVoejsX3AS8i0hf0Nhto2PVJtWLfc48fDGfdFEF-CBS2zp0e7TcQFvtpdH8Bvz8V49w9x/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq5sQPPpj8Lt7nq1Cho4N340buTnxQNisRaJUBAaYjdn8DOK7PlCAxtsndu2R7RAkgjJH6jdtAVoejsX3AS8i0hf0Nhto2PVJtWLfc48fDGfdFEF-CBS2zp0e7TcQFvtpdH8Bvz8V49w9x/s320/Screen+6.png" width="221" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #a96800; font-family: Helvetica; font-size: 12px;">
<span style="color: black;">If I </span>press for long time<span style="color: black;"> I get this</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjttYLjy6uPeeeoT9kgXuexLVpyEV1HEj9sIRfNasOyoUMj2ieBcNAvjsqUKz8bmIlmGOBJd_0pMUP_7rYOBAAcJwcBmIMnI-PgtUdvw_JHaRQ4BuUxg3XtEmE-bbArSk20_bJ999RSrwUi/s1600/Screen+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjttYLjy6uPeeeoT9kgXuexLVpyEV1HEj9sIRfNasOyoUMj2ieBcNAvjsqUKz8bmIlmGOBJd_0pMUP_7rYOBAAcJwcBmIMnI-PgtUdvw_JHaRQ4BuUxg3XtEmE-bbArSk20_bJ999RSrwUi/s320/Screen+7.png" width="218" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
and even I can see <span style="color: #00a3d7;">Rotate gesture</span>,, </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEsnLiEEwdepUkt1k9AQgNgqDc86CXMKXqp22wHw-Gj7yIz0L6oCyQVaZ4VnpY6VERXP1eZmLheIHsu-gtldNyk_unAFJ4taZxbfhFsPccp64JlC7Vb_qNhAXF5GeDasYafDuMoF9jrNZw/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEsnLiEEwdepUkt1k9AQgNgqDc86CXMKXqp22wHw-Gj7yIz0L6oCyQVaZ4VnpY6VERXP1eZmLheIHsu-gtldNyk_unAFJ4taZxbfhFsPccp64JlC7Vb_qNhAXF5GeDasYafDuMoF9jrNZw/s320/Screen+8.png" width="220" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <span style="font-size: 14px;"><a href="https://www.opendrive.com/files?M182OTQxOTkwX285WFZZ" target="_blank"><span style="color: #38761d;"><b>GestureDemo.zip (68.3 KB)</b></span></a></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-46482665112512708712013-01-22T00:54:00.000-08:002013-04-04T02:05:33.273-07:00Timer Countdown in iPhone Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<b style="font-family: Helvetica; font-size: 12px;">Hola,, iCoder,, </b><span style="color: #4f7a28; font-family: Helvetica; font-size: 12px;"><b>RDC</b></span><b style="font-family: Helvetica; font-size: 12px;"> is here</b><br />
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
What's up <span style="color: #0061ff;">guys</span>, today we are going to learn one simple but important concept in iPhone application development.. Time Countdown using NSTime Class.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #7b219f; font-family: Helvetica; font-size: 12px;">
<b><i>At the end of this Tutorial you can find Complete Source code zip file.</i></b></div>
<div style="color: #7b219f; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b><i></i></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So stay with me, and do it step by step by .. don't forget to drop me a message or comment.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN6Zgz3knaz7qEDx1ab7u9juY3p3AvD74HTiQEoWB8eOdf776HX1d6oF8sodWBeZYapW-va7hUVPgyp70bxcEaO0oyQwCVgjOvZDElQS2jRXLF9dSZPHRt4q7zk3xMiQbJ4_Iambip6aSE/s1600/Screen+0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN6Zgz3knaz7qEDx1ab7u9juY3p3AvD74HTiQEoWB8eOdf776HX1d6oF8sodWBeZYapW-va7hUVPgyp70bxcEaO0oyQwCVgjOvZDElQS2jRXLF9dSZPHRt4q7zk3xMiQbJ4_Iambip6aSE/s320/Screen+0.png" width="164" /></a></div>
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Note : This Application Developed Using : iOS 6. , Xcode 4.6, and MAC OS X Lion 10.8.3</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - I (Create New Project)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Let's Fire Xcode!!</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to File --> New --> Project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now we can see a Pop up Window for selecting our application templet </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So make sure you select Application in iOS option on your Left hand side.</div>
<div style="font-family: Helvetica; font-size: 12px;">
then select <b>Single View Application</b> as shown in below picture and Go for Next..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s1600/Screen+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3DqIK4_QZJK2hxfjpoZDoj4G5JzE5vH5DqsL0cSSbeYYIqbjfHiFnK7Akl8KFLDQw4DlcBDFJEupHPNfP9k-bAHXzEE_KlDYqRFp7sfl5X8qhmTtJMjiFm7gSA9TlVtq-mgSfOfavpQqe/s320/Screen+1.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
In the Next Window we need to put Our Project Details this way</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
--------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Product Name : <b>TimerDemo<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Organization Name :<b>RDCWorld<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Company Identifier : <b>com.rdcworld <span style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Class Prefix : (leave it blank for now)<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
|<span class="Apple-tab-span" style="white-space: pre;"> </span>Devices : <b>iPhone<span class="Apple-tab-span" style="white-space: pre;"> </span></b>|</div>
<div style="font-family: Helvetica; font-size: 12px;">
--------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<i>Note : Don't forget to Make Tick mark on "Use Automatic Reference Counting" option.</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDapQVRja2Z0L2HrXhjU84-lYkiSn8oTK346ooBRXQ0r49yW-7UDxqchF7DpnvEIM2Wk96HTKpCsLr_oMvQExFyZ4DN-m7Wy1A6J1Z4So8NdwAvfCPPS1hYaQeRpPxxE9MAcn8Ls-N6_kb/s1600/Screen+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDapQVRja2Z0L2HrXhjU84-lYkiSn8oTK346ooBRXQ0r49yW-7UDxqchF7DpnvEIM2Wk96HTKpCsLr_oMvQExFyZ4DN-m7Wy1A6J1Z4So8NdwAvfCPPS1hYaQeRpPxxE9MAcn8Ls-N6_kb/s320/Screen+2.png" width="320" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go to Next --> Create.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now you can see Xcode default dashboard with our newly created project .</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - II (Design UI)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We need to add one UITextField, and few UIButtons on our screen to get it work.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So, Just open ViewController.xib file you can see default blank layout</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Let's drag UINavigationBar from Object library double click on it and give title as "Countdown Timer", (we will use this for just showing app Title)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. Select main view and change background to <span style="color: #874efe;">Purple</span> Colour or what you like or leave it as default.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. Drag one UILabel from Object Lib and update its text => <i>Timer Status , </i>and expand its width as shown in screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. now add Three UIButtons, give them names as <b>Start</b>, <b>Pause</b>,and <b>Reset</b>.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
see below screen shot.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuHLvWB1WJfWc3B5fRojmT8sBTwDDx76Pb6A3Px8tUHu0v_3zoPa6hdEgZRLFPK3Wpx7Q6RO0WXANCzGYaX-blr7WjNjUBzS7y84vc5FGPxw7RdwsvV-hAWqQYCCNoFENqsX5Omjr_AWNL/s1600/Screen+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuHLvWB1WJfWc3B5fRojmT8sBTwDDx76Pb6A3Px8tUHu0v_3zoPa6hdEgZRLFPK3Wpx7Q6RO0WXANCzGYaX-blr7WjNjUBzS7y84vc5FGPxw7RdwsvV-hAWqQYCCNoFENqsX5Omjr_AWNL/s320/Screen+3.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - III (Create IBOutlet and IBActions)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
We are going to create IBOutlet for UITextField,UILabel and IBAction method for UIButton.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay, Now select Assistant Editor on Top Right side</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2_Wft23URl7_2ROPZbjWquqNOAtnM-_h97HqTdahicAI088XtR8k6VHctN7cZ9nx6bHpPljBJiCP4j-BOeNYslD0UHm2xM77sWYnUbR_93uB2eYYTRu_yRkbP5Cfm7OaID_nBCqbGd7F/s1600/Screen+11.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can see our ViewController.xib (Left side) + ViewController.h (Right side) opened together.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Fist is First, Create IBOutlet for UITextField,UILabel</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Hold Ctrl button--> Select UILabel named "Timer Status" --> drag cursor to ViewController.h(right side) file, when your cursor is between <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@interface </span><span style="font-family: Menlo; font-size: 11px;">and</span><span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;"> @end</span><span style="font-family: Menlo; font-size: 11px;">.</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
while leaving cursor here you will get Popup Window </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
just put Name : "<span style="font-family: Menlo; font-size: 11px;">timerLabel</span>" and click on Connect.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigClZRx5rh3T1w9jEOQwoNFDfEOJbLa12OTOC83TZba_cysJcUE131dxgKFH92V83JrG2N94wXL5fJVxMldgIBk3IUOdy-rIE9saK8ay3S0r5Hkne7GdW24MYPlzhPAFT0G-ogL9hsUpSU/s1600/Screen+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigClZRx5rh3T1w9jEOQwoNFDfEOJbLa12OTOC83TZba_cysJcUE131dxgKFH92V83JrG2N94wXL5fJVxMldgIBk3IUOdy-rIE9saK8ay3S0r5Hkne7GdW24MYPlzhPAFT0G-ogL9hsUpSU/s1600/Screen+5.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
now you can see below code line in your ViewController.h file (in right side)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UILabel</span><span style="color: black;"> *timerLabel;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
do the same for UITextField, and UIButtons (one by one) give the name "<span style="font-family: Menlo; font-size: 11px;">timerValueTextField</span>", "<span style="font-family: Menlo; font-size: 11px;">startButton</span>", "<span style="font-family: Menlo; font-size: 11px;">pauseButton</span>" and "<span style="font-family: Menlo; font-size: 11px;">resetButton</span>" respectively.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
after adding IBOutlet for all you can see IBOutlet property added to your header file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *timerValueTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *startButton;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *pauseButton;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *resetButton;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
2. Create IBAction methods</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
2.1 Select UIButton (which says -'Start') --> Right Click on it </div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
2.2 Click on <span style="color: #4f7a28;"><b>Touchup Inside</b></span> in "Sent Events" option and drag cursor just below to new created IBOutlets, and put the method name "<span style="color: black; font-family: Menlo; font-size: 11px;">startTimer</span>" in pop window</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_mE6W_6Z4Ku-l3MRpHYOkaQaGwcdlyZ33RPQSmCCmJn5PZl9ekVTTRIqGx-CHWio-tgAxHv6FzRW47K1T1VNhVb32ZzmoIqf51xC7vIBmGP0JhJuJZSwem7FiRGdN0CpsFYYqeLAh7y_4/s1600/Screen+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_mE6W_6Z4Ku-l3MRpHYOkaQaGwcdlyZ33RPQSmCCmJn5PZl9ekVTTRIqGx-CHWio-tgAxHv6FzRW47K1T1VNhVb32ZzmoIqf51xC7vIBmGP0JhJuJZSwem7FiRGdN0CpsFYYqeLAh7y_4/s1600/Screen+6.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
you can see IBAction method added in header file </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startTimer:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
2.3 do the same for next two Buttons and give methods name as<span style="font-family: Menlo; font-size: 11px;"> "</span><span style="color: black; font-family: Menlo; font-size: 11px;">stopTimer</span><span style="font-family: Menlo; font-size: 11px;">", </span>and<span style="font-family: Menlo; font-size: 11px;"> "</span><span style="color: black; font-family: Menlo; font-size: 11px;">resetTimer</span><span style="font-family: Menlo; font-size: 11px;">" </span>respectively<span style="font-family: Menlo; font-size: 11px;">.</span></div>
<div style="color: #232323; font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
this time you can see three new IBAction methods created in header file</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)<span style="color: black;">stopTimer</span>:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="color: #232323; font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)<span style="color: black;">resetTimer</span>:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Done!! now back to Standard Editor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2IufP2GlBJ_44ZAo-A7oXVc2DtGsIFpq8SxKCt2QPqpKlPlt_knGzZhyphenhyphenILpqoMlmUqNGB8tDIQFOwum9fbcW1QOMBdqeptDS_r0VOjVCm11gC9RJslZrH2gH2mKApJho5mAEPMpJie2FS/s1600/Screen+19.png" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>PHASE - IV (Writing Code)</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Controller Class (ViewController) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">1. open </span><b>ViewController.h</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. declare an integer for Timer Value</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">int</span> secondsLeft;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. create NSTimer instance with property</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>weak<span style="color: black;">) </span><span style="color: #703daa;">NSTimer</span><span style="color: black;"> *timer;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. just before <span style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">@end </span>add one IBAction method to handle keypad go</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.h</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TimerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 22/01/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> ViewController : <span style="color: #703daa;">UIViewController</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">int</span> secondsLeft;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>weak<span style="color: black;">) </span><span style="color: #703daa;">NSTimer</span><span style="color: black;"> *timer;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UILabel</span><span style="color: black;"> *timerLabel;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UITextField</span><span style="color: black;"> *timerValueTextField;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *startButton;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *pauseButton;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIButton</span><span style="color: black;"> *resetButton;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startTimer:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)stopTimer:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)resetTimer:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender;</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now come to <b>ViewController.m</b> file , open it</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px;">
<b>Here is the Heart of Application</b></div>
<div style="color: #e32400; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. To create Timer Countdown, we need to create NSTime class object with some properties like Time interval and the selector method so we can handle any action with Timer.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSTimer *</span><span style="color: #4f8187;">timer</span><span style="color: black;"> = [</span><span style="color: #703daa;">NSTimer</span><span style="color: black;"> </span>scheduledTimerWithTimeInterval<span style="color: black;">:</span><span style="color: #272ad8;">1.0</span><span style="color: black;"> </span>target<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>selector<span style="color: black;">:</span><span style="color: #bb2ca2;">@selector</span><span style="color: black;">(runScheduledTask:) </span>userInfo<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>repeats<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Here we have 1 second time interval, and selector method name "<span style="font-family: Menlo; font-size: 11px;">runScheduledTask</span>"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. also we need to provide body for selector method</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)runScheduledTask: (<span style="color: #703daa;">NSTimer</span> *) runningTimer { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">int</span> hours, minutes, seconds;</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondsLeft<span style="color: black;">--;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
hours = <span style="color: #4f8187;">secondsLeft</span> / <span style="color: #272ad8;">3600</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
minutes = (<span style="color: #4f8187;">secondsLeft</span> % <span style="color: #272ad8;">3600</span>) / <span style="color: #272ad8;">60</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
seconds = (<span style="color: #4f8187;">secondsLeft</span> %<span style="color: #272ad8;">3600</span>) % <span style="color: #272ad8;">60</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">timerLabel</span>.<span style="color: #703daa;">text</span> =[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"Time Remaining %02d:%02d:%02d"</span>, hours, minutes, seconds]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">secondsLeft</span>==<span style="color: #272ad8;">0</span>) { </div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">timer</span> <span style="color: #3d1d81;">invalidate</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">timerLabel</span>.<span style="color: #703daa;">text</span> = <span style="color: #d12f1b;">@"Time up!!"</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. we can stop Timer using Invalidate </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;">[</span><span style="color: #4f8187;">timer</span><span style="color: black;"> </span>invalidate<span style="color: black;">];</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So Finally our <span style="color: #008400; font-family: Menlo; font-size: 11px;"><b>ViewController.m</b></span> file look like</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// ViewController.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TimerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 22/01/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> </span>ViewController<span style="color: black;"> ()</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> timer;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> timerValueTextField;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> timerLabel;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> pauseButton;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> startButton;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> resetButton;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span>pauseButton<span style="color: black;"> </span><span style="color: #3d1d81;">setEnabled</span><span style="color: black;">:</span><span style="color: #bb2ca2;">NO</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">resetButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">NO</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)runScheduledTask: (<span style="color: #703daa;">NSTimer</span> *) runningTimer { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">int</span> hours, minutes, seconds;</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondsLeft<span style="color: black;">--;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
hours = <span style="color: #4f8187;">secondsLeft</span> / <span style="color: #272ad8;">3600</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
minutes = (<span style="color: #4f8187;">secondsLeft</span> % <span style="color: #272ad8;">3600</span>) / <span style="color: #272ad8;">60</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
seconds = (<span style="color: #4f8187;">secondsLeft</span> %<span style="color: #272ad8;">3600</span>) % <span style="color: #272ad8;">60</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">timerLabel</span>.<span style="color: #703daa;">text</span> =[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"Time Remaining %02d:%02d:%02d"</span>, hours, minutes, seconds]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">secondsLeft</span>==<span style="color: #272ad8;">0</span>) { </div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">timer</span> <span style="color: #3d1d81;">invalidate</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">timerLabel</span>.<span style="color: #703daa;">text</span> = <span style="color: #d12f1b;">@"Time up!!"</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)startTimer:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">pauseButton</span><span style="color: black;"> </span>setTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Pause"</span><span style="color: black;"> </span>forState<span style="color: black;">:</span>UIControlStateNormal<span style="color: black;">]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>secondsLeft<span style="color: black;"> = [</span>timerValueTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> </span><span style="color: #3d1d81;">intValue</span><span style="color: black;">]; </span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// This will allow 10,000 Hours Timer Limits</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">secondsLeft</span> ><span style="color: #272ad8;">0</span> && <span style="color: #4f8187;">secondsLeft</span> <<span style="color: #272ad8;">36000001</span> ) { </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">timer</span><span style="color: black;"> = [</span><span style="color: #703daa;">NSTimer</span><span style="color: black;"> </span>scheduledTimerWithTimeInterval<span style="color: black;">:</span><span style="color: #272ad8;">1.0</span><span style="color: black;"> </span>target<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>selector<span style="color: black;">:</span><span style="color: #bb2ca2;">@selector</span><span style="color: black;">(runScheduledTask:) </span>userInfo<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>repeats<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">startButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">NO</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">pauseButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">YES</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">resetButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">YES</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{ </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> *alert = [[</span><span style="color: #703daa;">UIAlertView</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@""</span><span style="color: black;"> </span>message<span style="color: black;">:</span><span style="color: #d12f1b;">@"Please! enter valid timer value"</span><span style="color: black;"> </span>delegate<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>cancelButtonTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"OK"</span><span style="color: black;"> </span>otherButtonTitles<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[alert <span style="color: #3d1d81;">show</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)stopTimer:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">if</span><span style="color: black;"> ([</span><span style="color: #d12f1b;">@"Pause"</span><span style="color: black;"> </span>isEqualToString<span style="color: black;">:[</span><span style="color: #4f8187;">pauseButton</span><span style="color: black;"> </span>titleForState<span style="color: black;">:</span>UIControlStateNormal<span style="color: black;">]]) {</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Paused"</span>);</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">pauseButton</span><span style="color: black;"> </span>setTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Resume"</span><span style="color: black;"> </span>forState<span style="color: black;">:</span>UIControlStateNormal<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">startButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">NO</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">pauseButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">YES</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">resetButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">NO</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">timer</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">timer</span> <span style="color: #3d1d81;">invalidate</span>]; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">int</span> hours, minutes, seconds;</div>
<div style="font-family: Menlo; font-size: 11px;">
hours = <span style="color: #4f8187;">secondsLeft</span> / <span style="color: #272ad8;">3600</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
minutes = (<span style="color: #4f8187;">secondsLeft</span> % <span style="color: #272ad8;">3600</span>) / <span style="color: #272ad8;">60</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
seconds = (<span style="color: #4f8187;">secondsLeft</span> %<span style="color: #272ad8;">3600</span>) % <span style="color: #272ad8;">60</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">timerLabel</span>.<span style="color: #703daa;">text</span> =[<span style="color: #703daa;">NSString</span> <span style="color: #3d1d81;">stringWithFormat</span>:<span style="color: #d12f1b;">@"Time paused at %02d:%02d:%02d"</span>, hours, minutes, seconds]; </div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">else</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Resumed"</span>);</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">pauseButton</span><span style="color: black;"> </span>setTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Pause"</span><span style="color: black;"> </span>forState<span style="color: black;">:</span>UIControlStateNormal<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">startButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">NO</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">pauseButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">YES</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">resetButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">YES</span>]; </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">timer</span><span style="color: black;"> = [</span><span style="color: #703daa;">NSTimer</span><span style="color: black;"> </span>scheduledTimerWithTimeInterval<span style="color: black;">:</span><span style="color: #272ad8;">1.0</span><span style="color: black;"> </span>target<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>selector<span style="color: black;">:</span><span style="color: #bb2ca2;">@selector</span><span style="color: black;">(runScheduledTask:) </span>userInfo<span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;"> </span>repeats<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">secondsLeft</span>==<span style="color: #272ad8;">0</span>) { </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span>(<span style="color: #d12f1b;">@"Time up!!"</span>); </div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">timer</span> <span style="color: #3d1d81;">invalidate</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #4f8187;">timerLabel</span>.<span style="color: #703daa;">text</span> = <span style="color: #d12f1b;">@"Time up!!"</span>; </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)resetTimer:(<span style="color: #bb2ca2;">id</span>)sender {</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span>startButton<span style="color: black;"> </span><span style="color: #3d1d81;">setEnabled</span><span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span>pauseButton<span style="color: black;"> </span><span style="color: #3d1d81;">setEnabled</span><span style="color: black;">:</span><span style="color: #bb2ca2;">NO</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">resetButton</span> <span style="color: #3d1d81;">setEnabled</span>:<span style="color: #bb2ca2;">NO</span>]; </div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">pauseButton</span><span style="color: black;"> </span>setTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"Pause"</span><span style="color: black;"> </span>forState<span style="color: black;">:</span>UIControlStateNormal<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span> (<span style="color: #4f8187;">timer</span> != <span style="color: #bb2ca2;">nil</span>) {</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #4f8187;">timer</span> <span style="color: #3d1d81;">invalidate</span>];</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">timerLabel</span><span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;"> = </span>@"Timer got reset!!"<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}<span style="color: #bb2ca2;">else</span>{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"timer is nil"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>timerValueTextField<span style="color: black;">.</span><span style="color: #703daa;">text</span><span style="color: black;">=</span><span style="color: #d12f1b;">@""</span><span style="color: black;">; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">IBAction</span>)keypadGoBack:(<span style="color: #bb2ca2;">id</span>)sender{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #4f8187;">timerValueTextField</span><span style="color: black;"> </span>resignFirstResponder<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>~ ~ ~ ~ ~ ~ ~ ~ ~ Application Delegate Class (AppDelegate) ~ ~ ~ ~ ~ ~ ~ ~ ~ </b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Make sure your AppDelegate file code should be default </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.h</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.h</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TimerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by KNSMac2 on 22/01/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span>ViewController<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span><span style="color: black;"> AppDelegate : </span>UIResponder<span style="color: black;"> <</span>UIApplicationDelegate<span style="color: black;">></span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> *window;</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>strong<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span><span style="color: #4f8187;">ViewController</span><span style="color: black;"> *viewController;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Finally our <b>AppDelegate.m</b> file look like </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// AppDelegate.m</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// TimerDemo</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Created by RDC on 22/01/13.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Copyright (c) 2013 RDC World. All rights reserved.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"AppDelegate.h"</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> AppDelegate</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)application:(<span style="color: #703daa;">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: #703daa;">NSDictionary</span> *)launchOptions{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> = [[</span><span style="color: #703daa;">UIWindow</span><span style="color: black;"> </span>alloc<span style="color: black;">] </span>initWithFrame<span style="color: black;">:[[</span><span style="color: #703daa;">UIScreen</span><span style="color: black;"> </span>mainScreen<span style="color: black;">] </span>bounds<span style="color: black;">]]; </span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;"> = [[</span>ViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>window<span style="color: black;">.</span><span style="color: #703daa;">rootViewController</span><span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>viewController<span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #4f8187;">window</span><span style="color: black;"> </span>makeKeyAndVisible<span style="color: black;">];</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>YES<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//for now leave rest all empty methods..</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="color: #232323; font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Okay wrap it up this application. let's Run it.</div>
<div style="font-family: Helvetica; font-size: 12px;">
we can Start, Pause, Resume and Stop Timer..</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWr-M0v6cg9Q4Q2fGFso3zgM4r3tBZi5CibHdw2IWioxgVmnPteoXIQqeDijrHz6eJHZb8mhLwgGSGpetLhdM7OKU1EKxsC1uqpNkcrBa2rwvnZHK9ozY-mnue9mteQNyQz55vaarchKbv/s1600/Screen+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWr-M0v6cg9Q4Q2fGFso3zgM4r3tBZi5CibHdw2IWioxgVmnPteoXIQqeDijrHz6eJHZb8mhLwgGSGpetLhdM7OKU1EKxsC1uqpNkcrBa2rwvnZHK9ozY-mnue9mteQNyQz55vaarchKbv/s320/Screen+8.png" width="221" /></a></div>
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we did it. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You can find complete project source code zip file here : <span style="font-size: 14px;"><a href="https://www.opendrive.com/files?M183MDI4NDA3XzBFcmk5" target="_blank"><span style="color: #38761d;"><b>TimerDemo.zip (67.22 KB)</b></span></a></span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I Would love to here your thoughts !! </div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-9553638417615176822013-01-12T06:56:00.000-08:002013-02-25T06:58:27.580-08:00Complier Directives in Objective-C <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Complier Directives in Objective-C </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
@, or "at" sign compiler directives, are as central to understanding Objective-C's gestalt as its ancestry and underlying mechanisms. It's the sugary glue that allows Objective-C to be such a powerful, expressive language, and yet still compile all the way down to C.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Interface & Implementation</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">1.</span><span style="color: black;"> </span>@class</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">2.</span><span style="color: black;"> </span>@interface</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">3.</span><span style="color: black;"> </span>@implementation</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">4.</span><span style="color: black;"> </span>@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Instance Variable Visibility</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">5.</span><span style="color: black;"> </span>@public</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">6.</span><span style="color: black;"> </span>@private</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">7.</span><span style="color: black;"> </span>@protected<span style="color: black;"> </span><span style="color: #008400;">//default</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">8.</span><span style="color: black;"> </span>@package</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Properties</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">09.</span><span style="color: black;"> </span>@property</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">10.</span><span style="color: black;"> </span>@synthesize</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">11.</span><span style="color: black;"> </span>@dynamic</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Protocols</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">12.</span><span style="color: black;"> </span>@protocol</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">13.</span><span style="color: black;"> </span>@required<span style="color: black;"> </span><span style="color: #008400;">//default</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">14.</span><span style="color: black;"> </span>@optional</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Exception Handling</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">15.</span><span style="color: black;"> </span>@try</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">16.</span><span style="color: black;"> </span>@catch</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">17.</span><span style="color: black;"> </span>@throw</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">18.</span><span style="color: black;"> </span>@finally</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Object Literals</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">19.</span><span style="color: black;"> </span>@" string "</div>
<div style="color: #272ad8; font-family: Menlo; font-size: 11px;">
20.<span style="color: black;"> </span>@42<span style="color: black;">, </span>@3.14<span style="color: black;">, </span>@YES<span style="color: black;">, @</span>'Z'</div>
<div style="color: #272ad8; font-family: Menlo; font-size: 11px;">
21.<span style="color: black;"> </span>@[<span style="color: black;"> </span>]</div>
<div style="color: #272ad8; font-family: Menlo; font-size: 11px;">
22.<span style="color: black;"> </span>@{<span style="color: black;"> </span>}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Objective-C Literals</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">24. </span>@selector<span style="color: black;"> ( )</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">25. </span>@protocol<span style="color: black;"> ( )</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
C Literals</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">26.</span><span style="color: black;"> </span>@encode<span style="color: black;"> ( )</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">27.</span> <span style="color: #bb2ca2;">@defs</span> ( )</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Optimizations</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">28.</span><span style="color: black;"> </span>@autoreleasepool<span style="color: black;"> { }</span></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">29.</span><span style="color: black;"> </span>@synchronized<span style="color: black;"> { }</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Compatibility</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">30.</span><span style="color: black;"> </span>@compatibility_alias</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now Details with Definition and Example</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Interface & Implementation</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>1. @class </b> : Used for class forward declarations. </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> Declares the names of classes defined elsewhere without having to import the class' header file.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Forward Class Declarations : Occasionally, @interface declarations will reference an external class in a property or as a parameter type. Rather than adding #import statements for each class, it's good practice to use forward class declarations in the header, and import them in the implementation.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example. if I want to use MyClass data In my MyViewController class. So in MyViewController.h file I do like this</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><UIKit/UIKit.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@class</span><span style="color: black;"> </span><span style="color: #4f8187;">MyClass</span><span style="color: black;">; </span>//or #import "MyClass.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyViewController : <span style="color: #703daa;">UIViewController</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Now I have to #import "MyClass.h" in my MyViewController.m File.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Advantages : Shorter compile times, less chance of cyclical references; you should definitely get in the habit of doing this if you aren't already.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>2. @interface<span class="Apple-tab-span" style="white-space: pre;"> </span></b> : Used to declare of Class / Interface or Category</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class/ Interface Declaration</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example : File name is "MyClass.h", I have created MyClass using NSObject Base Class</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : NSObject</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Category Declaration</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example : File name is "NSString+MYCustomString.h". I have created MyCustomString Category using NSString Base Class.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> NSString (MYCustomString)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>3. @implementation </b>: Used to define a Class / Interface or Category</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Class/ Interface Definition</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example : File name is "MyClass.m", I have implemented MyClass using "MyClass.h" header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"MyClass.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> MyClass</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Category Definition</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example : File name is "NSString+MYCustomString.m". I have implemented MyClass using "MYCustomString.h" header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"NSString+MYCustomString.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> NSString (MYCustomString)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>4. @end </b>: Used to indicates ends the declaration, definition of Class/ Interface, Category or Protocols.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example: We can see in every Class/Protocol/Interface/Category like blow code</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"MyClass.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> MyClass</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Instance Variable Visibility</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>5. @public </b>: Declares that instance variables as public access to all classes.<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>6. @private</b> :Declares that instance variables only available in this class.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>7. @protected</b> : Declares that instance variables available in this class and its derived classes as well, it's default property.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>8. @package</b> It means the instance variable member is accessible only from the framework in which it is defined. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example. In "MyClass.h" file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : NSObject {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@public</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *firstName;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *lastName;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@private</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *personalID;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>@package</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">int</span> age;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@protected</span><span style="color: black;"> </span>// this is default</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *address;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Properties</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>09. @property</b> : Declares a property of variable with exact behavior of property using property modifiers like strong, weak etc.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example: In my "MyClass.h" file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : NSObject {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// define variable property</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> <span style="color: #703daa;">NSString</span> *firstName;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//define variable property with exact behavior</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *lastName;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : <span style="color: #703daa;">NSObject</span>{</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">float</span> rate;</div>
<div style="font-family: Menlo; font-size: 11px;">
NSString *name;</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>10. @synthesize</b>: Tells compiler to automatically generate setter and getter methods for the given property in its header file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example: In my MyClass.m file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"MyClass.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> MyClass</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> firstName;</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> lastName;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>11. @dynamic </b>: directive essentially tells the compiler "don't worry about it, its setter and getter methods are on the way."</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So we use dynamic directive in two situations</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>a. if we are going to write setter and getter ourselves for adding some extra logic</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>b. or just tells the compiler that the getter and setter methods are implemented not by the class itself</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> but somewhere else (like the superclass)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Super class:</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">retain</span>) NSButton *someButton;</div>
<div style="font-family: Menlo; font-size: 11px;">
...</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> someButton;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Subclass:</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) </span>IBOutlet<span style="color: black;"> NSButton *someButton;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
...</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@dynamic</span> someButton;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Protocols</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>12. @protocol :</b> Marks the start of protocol declaration.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> Defines a set of methods to be implemented by any class conforming to the protocol, </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>as if they were added to the interface of that class.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@protocol</span> MyProtocol <<span style="color: #703daa;">NSObject</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//declare method here</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : <span style="color: #703daa;">NSObject</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>13. @required</b> : Used to declare protocol method implementation is must when a class use adopt this protocol. Protocol methods are required by default.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@protocol</span> MyProtocol <<span style="color: #703daa;">NSObject</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//this is default (required method)</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getUserName;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : <span style="color: #703daa;">NSObject</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>14. @optional</b> : Used to declare protocol method implementation is optional when a class use adopt this protocol.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@protocol</span> MyProtocol <<span style="color: #703daa;">NSObject</span>></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@required</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getUserName;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@optional</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSString</span> *) getUserID;</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">BOOL</span>) isValidUser;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> MyClass : <span style="color: #703daa;">NSObject</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Exception Handling</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>15. @try :</b> defines a block of code that can throw an exception.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>16. @catch</b> : define block of code to handle exception thrown by try block, this is usually an NSException object.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>17. @finally </b>: defines a block of code that executed whether an exception is thrown or not.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="font-family: Helvetica; font-size: 12px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #703daa;">MyClass</span> *obj = [[MyClass alloc] init];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@try<span style="color: black;"> {</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
[obj noSuchMethod];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@catch</span> (NSException *e) {</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> NSLog(</span>@"The Exception name is %@ and the reason is %@"<span style="color: black;">,[e name], [e reason]);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@finally<span style="color: black;"> {</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
[obj release];//no use after ARC enabled</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>18. @throw </b>: defines throws an exception object</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
NSException<span style="color: black;">* myException = [</span>NSException</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">exceptionWithName</span>:<span style="color: #d12f1b;">@"IndexOutOfBoundsException"</span></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">reason</span><span style="color: black;">:</span>@"Attempted to access an array index that is out of bounds"</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">userInfo</span>:<span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@throw</span> myException;</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// [myException raise]; /* equivalent to throwing the exception, above */</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Object Literals</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>19. @" string " </b>: Declares a content NSString object. Such strings do not need to be retained or released.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span><span style="color: black;"> *str = </span>@"This is a constant string."<span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>20. @42, @3.14, @YES, @'Z' </b>: Returns an NSNumber object initialized with pertinent class constructor</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// character literals.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *theLetterZ = @</span><span style="color: #272ad8;">'Z'</span><span style="color: black;">; </span>// equivalent to [NSNumber numberWithChar:'Z']</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// integral literals.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *fortyTwo = </span><span style="color: #272ad8;">@42</span><span style="color: black;">; </span>// equivalent to [NSNumber numberWithInt:42]</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *fortyTwoUnsigned = </span><span style="color: #272ad8;">@42</span><span style="color: black;">U; </span>// equivalent to [NSNumber numberWithUnsignedInt:42U]</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *fortyTwoLong = </span><span style="color: #272ad8;">@42</span><span style="color: black;">L; </span>// equivalent to [NSNumber numberWithLong:42L]</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *fortyTwoLongLong = </span><span style="color: #272ad8;">@42</span><span style="color: black;">LL; </span>// equivalent to [NSNumber numberWithLongLong:42LL]</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// floating point literals.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *piFloat = </span><span style="color: #272ad8;">@3.141592654F</span><span style="color: black;">; </span>// equivalent to [NSNumber numberWithFloat:3.141592654F]</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *piDouble = </span><span style="color: #272ad8;">@3.1415926535</span><span style="color: black;">; </span>// equivalent to [NSNumber numberWithDouble:3.1415926535]</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// BOOL literals.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *yesNumber = </span><span style="color: #272ad8;">@YES</span><span style="color: black;">; </span>// equivalent to [NSNumber numberWithBool:YES]</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSNumber</span><span style="color: black;"> *noNumber = </span><span style="color: #272ad8;">@NO</span><span style="color: black;">; </span>// equivalent to [NSNumber numberWithBool:NO]</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>21. @[ ]</b> : Returns an NSArray object initialized with the comma-delimited list of objects as its contents.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span><span style="color: black;"> *myArray = </span><span style="color: #272ad8;">@[</span>@"one"<span style="color: black;">,</span>@"two"<span style="color: black;">,</span>@"three"<span style="color: #272ad8;">]</span><span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
is same as</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *myArray = [<span style="color: #703daa;">NSArray</span> <span style="color: #3d1d81;">arrayWithObjects</span>:<span style="color: #d12f1b;">@"one"</span>,<span style="color: #d12f1b;">@"two"</span>,<span style="color: #d12f1b;">@"three"</span>, <span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>22. @{ } :</b> Returns an NSDictionary object initialized with the specified key-value pairs as its contents, in the format: @{@"someKey" : @"theValue"}.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example : </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSDictionary</span><span style="color: black;"> *myDictionary = </span><span style="color: #272ad8;">@{</span>@"userName"<span style="color: black;"> : </span>@"rdc"<span style="color: black;">, </span>@"password"<span style="color: black;">:</span>@"testPwd"<span style="color: #272ad8;">}</span><span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
is same as</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSDictionary</span><span style="color: black;"> *myDictionary2 = [</span><span style="color: #703daa;">NSDictionary</span><span style="color: black;"> </span><span style="color: #3d1d81;">dictionaryWithObjectsAndKeys</span><span style="color: black;">:</span>@"userName"<span style="color: black;">, </span>@"rdc"<span style="color: black;">, </span>@"password"<span style="color: black;">,</span>@"testPwd"<span style="color: black;">, </span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//nil to signify end of objects and keys.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>23. @( ) </b>: Dynamically evaluates the boxed expression and returns the appropriate object literal based on its value</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example: In my "MyClass.m" file</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"MyClass.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@implementation<span style="color: black;"> MyClass</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) boxedExpressions{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// numbers.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSNumber</span><span style="color: black;"> *smallestInt = </span><span style="color: #272ad8;">@(</span><span style="color: black;">-</span><span style="color: #78492a;">INT_MAX</span><span style="color: black;"> - </span><span style="color: #272ad8;">1)</span><span style="color: black;">; </span>// [NSNumber numberWithInt:(-INT_MAX - 1)]</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSNumber</span><span style="color: black;"> *piOverTwo = </span><span style="color: #272ad8;">@(</span><span style="color: #78492a;">M_PI</span><span style="color: black;"> / </span><span style="color: #272ad8;">2)</span><span style="color: black;">; </span>// [NSNumber numberWithDouble:(M_PI / 2)]</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// enumerated types.</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">typedef</span> <span style="color: #bb2ca2;">enum</span> { Red, Green, Blue } Color;</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSNumber</span><span style="color: black;"> *favoriteColor = </span><span style="color: #272ad8;">@(</span><span style="color: #31595d;">Green</span><span style="color: #272ad8;">)</span><span style="color: black;">; </span>// [NSNumber numberWithInt:((int)Green)]</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// strings.</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #703daa;">NSString</span><span style="color: black;"> *path = </span><span style="color: #272ad8;">@(</span><span style="color: #3d1d81;">getenv</span><span style="color: black;">(</span><span style="color: #d12f1b;">"PATH"</span><span style="color: black;">)</span><span style="color: #272ad8;">)</span><span style="color: black;">; </span>// [NSString stringWithUTF8String:(getenv("PATH"))]</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSArray</span> *pathComponents = [path <span style="color: #3d1d81;">componentsSeparatedByString</span>:<span style="color: #d12f1b;">@":"</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Objective-C Literals</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>24. @selector ( method_name ) : </b>Returns the selector type 'SEL' of the given Objective-C method. Generates compiler warning if the method isn’t declared or doesn’t exist.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ViewController.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@implementation</span> ViewController</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">SEL</span> aMethodSelector = <span style="color: #bb2ca2;">@selector</span>(aMethod);</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span> <span style="color: #3d1d81;">performSelector</span>:aMethodSelector];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>)aMethod{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"aMethod called"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>25. @protocol (protocol_name ) </b>: Returns a Protocol * pointer to the protocol with the specified name.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
For example to check if an object conforms to a protocol. You can then cast it to an object conforming to that protocol so that you can call protocol methods on it, without having to know which kind of class the object is:<br />
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">Protocol</span> *aProtocol = <span style="color: #bb2ca2;">@protocol</span>(ProtocolName);<br />
<span style="color: #bb2ca2;">if</span> ([sender conformsToProtocol:aProtocol])<br />
{<br />
<span style="color: #bb2ca2;">id</span> senderWithProtocol = (<span style="color: #bb2ca2;">id</span> )sender;<br />
<span style="color: #bb2ca2;">BOOL</span> wtf = [senderWithProtocol aProtocolMethod];<br />
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>C Literals</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>26. @encode ( type_spec)</b> : Returns the character string encoding of a type.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) aMethod<br />
{<br />
<span style="color: #bb2ca2;">char</span> *enc1 = <span style="color: #bb2ca2;">@encode</span>(<span style="color: #bb2ca2;">int</span>); <span style="color: #008400;">/* enc1 = "i" */</span> </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *enc2 = <span style="color: #bb2ca2;">@encode</span>(<span style="color: #bb2ca2;">id</span>); <span style="color: #008400;">/* enc2 = "@" */</span> </div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">char</span> *enc3 = <span style="color: #bb2ca2;">@encode</span>(<span style="color: #bb2ca2;">@selector</span>(aMethod)); <span style="color: #008400;">/* enc3 = ":" */</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>/* practical example: */</div>
<div style="font-family: Menlo; font-size: 11px;">
CGRect rect = CGRectMake(<span style="color: #272ad8;">0</span>, <span style="color: #272ad8;">0</span>, <span style="color: #272ad8;">100</span>, <span style="color: #272ad8;">100</span>);<br />
NSValue *v = [NSValue value:&rect withObjCType:<span style="color: #bb2ca2;">@encode</span>(CGRect)];<br />
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px;">
<span style="color: black; font-family: Helvetica;"><b>27. @defs ( )</b> : </span>The @defs directive returns the layout of an Objective-C class.</div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px;">
Example:</div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">struct</span> { <span style="color: #bb2ca2;">@defs</span>( NSObject) }</div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 15px; min-height: 15px;">
<br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Optimizations</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>28. @autoreleasepool { } </b>: create autoreleasepool to dealloc real eased objects when execution complete at the end of block.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
If your code contains a tight loop that creates lots of temporary objects, you can use the @autorelease directive to optimize for these short-lived, locally-scoped objects by being more aggressive about how they're deallocated. @autoreleasepool replaces and improves upon the old NSAutoreleasePool, which is significantly slower, and unavailable with ARC.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
You should not declare a variable inside the @autoreleasepool block.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
The @autoreleasepool is about six times faster than using NSAutoreleasePool, therefore Apple recommends its use even for non-ARC projects.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;">-(</span><span style="color: #bb2ca2;">void</span><span style="color: black;">) aMethod<br />
{<br />
</span><span style="color: #bb2ca2;">@autoreleasepool</span><span style="color: black;"><br />
{<br />
</span>/* code that creates a large number of temporary objects */<span style="color: black;"><br />
}<br />
}</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px;">
<span style="color: black; font-family: Helvetica;"><b>29. @synchronized { }</b> : </span>Encapsulates code in a <span style="color: #0088cc;">mutex lock</span>. It ensures that the block of code and the locked object can only be accessed by one thread at a time.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example :</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) aMethodWithObject:(<span style="color: #bb2ca2;">id</span>)object<br />
{<br />
<span style="color: #bb2ca2;">@synchronized</span>(object)<br />
{<br />
<span style="color: #008400;">/* code that works with locked object */</span><br />
}<br />
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px;">
<b>Compatibility</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px;">
<span style="color: black; font-family: Helvetica;"><b>30. @compatibility_alias :</b> </span>Allows you to define an alias name for an existing class. The first parameter is the alias for a class name, a class with this name must not exist. The second parameter is the name of an existing class that the alias refers to.</div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #323333; font-family: 'Lucida Grande';">Example : in </span>MyClass.h file</div>
<div style="color: #323333; font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Foundation/Foundation.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span>"ExistingClassName.h"</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@interface</span> <span style="color: #4f8187;">MyClass</span> : NSObject</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@end</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@compatibility_alias</span> AliasClassName ExistingClassName;</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764152 76.949115699999979 13.466782199999999 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-46402307454666778142013-01-02T07:51:00.000-08:002013-10-18T04:42:05.766-07:00The Complete Guide for Starting iPhone Application Development<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
So you are looking for an iPhone application development, and want to write it yourself?</div>
<div style="font-family: Helvetica; font-size: 12px;">
Great!! This blog will help you get started.. even If you are not familiar with Objective-c and any Mac OS X coding like me,</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
When I wrote my first iPhone application I had worked as Java developer so it was new journey for me to become iOS developer..</div>
<div style="font-family: Helvetica; font-size: 12px;">
but I would say I just followed the way and every day I made examples and notes.. so here is the place I would like to share with you, what I have been learning.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Please feel free to drop comment below, give your idea, always welcome by RDC :)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
The best way to learn is by working through lots of examples.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I spent hours and hours finding out the best resources to learn how to develop apps for iPhone.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So first is first, Here are the steps I have mentioned, you should go one by one.</div>
<div style="font-family: Helvetica; font-size: 12px;">
Meanwhile I am trying to post More blogs to describes all these important contents.<br />
<br />
#RDC# </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br />
1. Understand iOS App Development Environment setup<br />2. Study Basics of Objective-C<br />3. Get Familiar with Xcode and Interface Builder and Simulator<br />4. Create HelloWorld App<br />5. Basic iOS Application Development<br /> -App LifeCycle<br /> -Basic UI Exercise<br /> -Advance View Controllers<br /> -NavigationController<br /> -TableViewController<br /> -CollectionViewController<br /> -TabBarController<br /> -SplitViewController<br /> -Delegates<br /> -ARC (Memory Management)<br /> -Run/Debug on Simulator/Apple Devices<br /><br />6. Advance iOS Application Development<br /> -Custom Views<br /> -Categories in Objective-C<br /> -Database (SQLite/ Core Data/pList/User-defaults)<br /> -MapKit<br /> -Camera<br /> -GPS<br /> -Webservices<br /> -JSON/XML<br /> -Run/Debug with Memory Analysis<br /> -Handling Exception with Zombie<br /> <br />7. Preparing Developer Program<br /> -Register at developer.apple.com<br /> -Create Developer/Distribution Certificates<br /> -Add/Configure iPhone to developer account<br /> -Push Notifications<br /> -Publish App to iTunes Store<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Table of Contents</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>[ 1 ]. Understand iOS App Development Environment setup</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1. Mac OS X Lion (10.8)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2. iOS SDK (6.1)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3. Xcode (4.6) with InterfaceBuilder</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4. Simulator and Apple Device</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5. Memory Analyzer instruments</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>[ 2 ]. Study Basics of Objective-C</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1. Oops concepts (object,class, data types)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2. Methods</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3. Understand Some Lib Classes</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.01 NSString</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.02 NSMutableString</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.03 NSArray</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.04 NSMutableArray</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.05 NSDictionary</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.06 NSMutableDictionary</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.07 NSLog</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.08 NSBundle</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.09 NSCoder</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.10 NSConnection</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.11 NSData, NSMutableData</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.12 NSError</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.13 NSException</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.14 NSIntegar</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.15 NSFormattar</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.16 NSNotification</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.17 NSOperation</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.18 NSSet</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.19 NSUrl</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3.20 NSUrlRequest, Response</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3. Messaging (calling method)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4. Properties </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.01 atomic</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.02 nonatomic</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.03 assign</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.04 retain</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.05 copy</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.06 strong</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.07 weak</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.08 readonly</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.09 readwrite</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4.10 unsafe_unretained<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5. Understand directives</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.01 @interface</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.02 @end</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.03 @implementation</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.04 @protocol</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.05 @property</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.06 @synthesize</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.07 @"string value"</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.08 @optional</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.09 @required</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.10 @public</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.11 @private</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.12 @package</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5.13 @protected</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>6. Protocol</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>7. Interface</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>8. Categories</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9. Memory Management</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9.1 alloc, dealloc, nil</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9.2 release</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9.3 retain</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9.4 autorelease</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9.5 copy</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>9.6 drain</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>10. Understand Delegate</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
--------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>[ 3 ]. Get Familiar with Xcode and Interface Builder and Simulator</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 1. Create App with different templets</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 2. Tool bars and Navigation bars in Xcode</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 3. Objects Lib, Lib Help</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 4. Debug and Execute application</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 5. Editor, Organizer</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 6. All the Inspectors</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 7. File Owner</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 8. First Responder</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 9. Hook up the Outlets & Actions</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>10. Understand Project Build Settings</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11. Memory Analyzer</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
----------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>[ 4 ]. Basic iOS Application Développement</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 1. Hello world app</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 2. Application Project Structure</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 3. Frameworks (Foundation, UIKit etc.)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 4. Understand .plist, .h, .m, .pch files use</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 5. App Delegate</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 6. Understand App and ViewController Life Cycle</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 7. Understand MVC design pattern in iOS</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 8. Change App icon</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> 9. Create Splash Screen</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>10. Connect Multiple UIControllers</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11. Get Familiar with Basic UI Items</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.01 UILabel</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.02 UIButton</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.03 UITextField</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.04 UIView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.05 UITableView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.06 UIAlertView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.07 UIActionSheet</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.08 UISegment</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.09 UISlider</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.10 UISwitch</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.11 UIProgressView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.12 UIActivityIndicatorView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.13 UIPageControl</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.14 UIImageView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.15 UITextView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.16 UIWebView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.17 MKMapView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.18 UIScrollView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.19 UIDatePicker</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.20 UIPickerView</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.21 UIGestures</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.22 UIViewController</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.23 UITabViewController, UITabBar</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.24 UINavigationBar</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11.25 UISearchBar</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>12. Study IBOutlet and IBAction</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>13. Debug the app using NSLog or BreakPoints</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>14. Test app with Simulator and Real Device</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
-------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>[ 5 ]. Advance iOS Application Développement</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>01.Design app for Portrait and Landscape modes</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>02. Design Custom Views</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>03.Create Model classes to store data on app level</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>04. Data Storage</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>04.1 Using Sqlite database</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>04.2.Using plist files</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>04.3.Using NSUserDefaults (app preferences)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>05. Delegates in iOS</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>06.Create Helper Class ( DBHelper, WebHelper)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>07.Understand Thread in iOS</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>08. AsynTask class (eg. image downloading)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>09. Core Data usage in application</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>10. Understand Category usage in application</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>11. Work with StoryBoards</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>12. Create application's binary file.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>13. Understand development and distribution certificate procedure</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>14. Understand the procedure to push app on iTunes Store. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
-------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>[ 6 ]. iOS App Development Learning Resources</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Books</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1. Apress - Beginning iOS 6 development </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2. Apress - Learn Objective-C on the Mac</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3. Oreilly - iPhone.App.Development.The.Missing.Manual</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4. Objective-C Programming: The Big Nerd Ranch Guide</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5. iOS 6 by Tutorials</div>
<div style="color: #323333; font-family: Helvetica; font-size: 12px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span>6. </span>Beginning iPhone SDK Programming with Objective-C</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Apple Official Documentations</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1. For Objective -c programming<span class="Apple-tab-span" style="white-space: pre;"> </span> </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>( http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html )</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2. Memory Management in iOS</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>(http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3. iOS Human Interface Guidelines</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>( https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Characteristics/Characteristics.html#//apple_ref/doc/uid/TP40006556-CH7-SW6 )</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; margin-left: 36px; text-indent: -36px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4. Automatic Reference Counting (ARC)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>( http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html )</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
Blogs with Good Tutorials Collection</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>1. http://www.raywenderlich.com/tutorials</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>2. http://mobileorchard.com/ios-development-tutorial-series-hello-world/</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>3. http://www.icodeblog.com/2010/04/05/ipad-programming-tutorial-hello-world/</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>4. http://mobile.tutsplus.com/category/tutorials/iphone/</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>5. http://www.edumobile.org/iphone/iphone-programming-tutorials/helloworld-example-in-xcode-4-iphone-os-4-3/</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>6. http://howtomakeiphoneapps.com/how-to-design-a-custom-uitableviewcell-from-scratch/1292/</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>7. http://iosdevelopertips.com/archives</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I would love to here your feedback!!</div>
<div>
<br /></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-44685673641725559322012-12-22T07:06:00.000-08:002013-02-25T07:07:56.965-08:00Variable property attributes or Modifiers in iOS<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
Variable property attributes or Modifiers</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Property Attributes Indicate Data Accessibility and Storage Considerations</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Use Accessor Methods to Get or Set Property Values</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">01.</span> atomic <span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #008400;">//default</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">02.</span> nonatomic</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">03.</span> strong=retain<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #008400;">//default</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">04.</span> weak= unsafe_unretained</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">05.</span> retain</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">06.</span> assign <span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #008400;">//default</span></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">07.</span> unsafe_unretained</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">08.</span> copy</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">09.</span> readonly</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #272ad8;">10.</span> readwrite <span class="Apple-tab-span" style="white-space: pre;"> </span> <span style="color: #008400;">//default</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>01. atomic </b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Atomic means only one thread access the variable(static type).</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Atomic is thread safe.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-but it is slow in performance</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-atomic is default behavior</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Atomic accessors in a non garbage collected environment (i.e. when using retain/release/autorelease) will use a lock to </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> ensure that another thread doesn't interfere with the correct setting/getting of the value.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-it is not actually a keyword.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example :</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">retain</span>) NSString *name;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>02. nonatomic</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Nonatomic means multiple thread access the variable(dynamic type).</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Nonatomic is thread unsafe.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-but it is fast in performance</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Nonatomic is NOT default behavior,we need to add nonatomic keyword in property attribute.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-it may result in unexpected behavior, when two different process (threads) access the same variable at the same time.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) NSString *name;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Explain:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Suppose there is an atomic string property called "name", and if you call [self setName:@"A"] from thread A, </div>
<div style="font-family: Helvetica; font-size: 12px;">
call [self setName:@"B"] from thread B, and call [self name] from thread C, then all operation on different thread will be performed serially which means if one thread is executing setter or getter, then other threads will wait. This makes property "name" read/write safe but if another thread D calls [name release] simultaneously then this operation might produce a crash because there is no setter/getter call involved here. Which means an object is read/write safe (ATOMIC) but not thread safe as another threads can simultaneously send any type of messages to the object. Developer should ensure thread safety for such objects.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
If the property "name" was nonatomic, then all threads in above example - A,B, C and D will execute simultaneously producing any unpredictable result. In case of atomic, Either one of A, B or C will execute first but D can still execute in parallel.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>03. strong (iOS4 = retain )</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-it says "keep this in the heap until I don't point to it anymore"</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-in other words " I'am the owner, you cannot dealloc this before aim fine with that same as retain"</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-You use strong only if you need to retain the object.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-By default all instance variables and local variables are strong pointers.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-We generally use strong for UIViewControllers (UI item's parents)</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-strong is used with ARC and it basically helps you , by not having to worry about the retain count of an object. ARC automatically releases it for you <span class="Apple-tab-span" style="white-space: pre;"> </span> when you are done with it.Using the keyword strong means that you own the object.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">strong</span>, <span style="color: #bb2ca2;">nonatomic</span>) ViewController *viewController;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> viewController;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>04. weak (iOS4 = unsafe_unretained )</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-it says "keep this as long as someone else points to it strongly"</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-the same thing as assign, no retain or release</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-A "weak" reference is a reference that you do not retain.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-We generally use weak for IBOutlets (UIViewController's Childs).This works because the child object only </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> needs to exist as long as the parent object does.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-a weak reference is a reference that does not protect the referenced object from collection by a garbage collector.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Weak is essentially assign, a unretained property. Except the when the object is deallocated the weak pointer is automatically set to nil</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example :</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> UIButton *myButton;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> myButton;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Explain:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Imagine our object is a dog, and that the dog wants to run away (be deallocated).</div>
<div style="font-family: Helvetica; font-size: 12px;">
Strong pointers are like a leash on the dog. As long as you have the leash attached to the dog, the dog will not run away. If five people attach their leash to one dog, (five strong pointers to one object), then the dog will not run away until all five leashes are detached.</div>
<div style="font-family: Helvetica; font-size: 12px;">
Weak pointers, on the other hand, are like little kids pointing at the dog and saying "Look! A dog!" As long as the dog is still on the leash, the little kids can still see the dog, and they'll still point to it. As soon as all the leashes are detached, though, the dog runs away no matter how many little kids are pointing to it.</div>
<div style="font-family: Helvetica; font-size: 12px;">
As soon as the last strong pointer (leash) no longer points to an object, the object will be deallocated, and all weak pointers will be zeroed out.</div>
<div style="font-family: Helvetica; font-size: 12px;">
When we use weak?</div>
<div style="font-family: Helvetica; font-size: 12px;">
The only time you would want to use weak, is if you wanted to avoid retain cycles </div>
<div style="font-family: Helvetica; font-size: 12px;">
(e.g. the parent retains the child and the child retains the parent so neither is ever released).</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>05. retain = strong</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-it is retained, old value is released and it is assigned</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-<span style="background-color: #eeeeee;">retain</span> specifies the new value should be sent -retain on assignment and the old value sent <span style="background-color: #eeeeee;">-release</span></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-retain is the same as strong.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-apple says if you write retain it will auto converted/work like strong only.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-methods like "alloc" include an implicit "retain"</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>retain<span style="color: black;">) NSString *name;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>06. assign </b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-assign is the default and simply performs a variable assignment</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-assign is a property attribute that tells the compiler how to synthesize the property's setter implementation</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-I would use <span style="background-color: #eeeeee;">assign</span> for C primitive properties and <span style="background-color: #eeeeee;">weak</span> for weak references to Objective-C objects.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">assign</span>) NSString *address;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> address;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>07. unsafe_unretained</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-unsafe_unretained is an ownership qualifier that tells ARC how to insert retain/release calls</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-unsafe_unretained is the ARC version of assign.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>unsafe_unretained<span style="color: black;">) NSString *nickName;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> nickName;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>08. copy</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-<span style="background-color: #eeeeee;">copy</span> is required when the object is mutable.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-<span style="background-color: #eeeeee;">copy</span> specifies the new value should be sent -copy on assignment and the old value sent <span style="background-color: #eeeeee;">-release</span>.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-copy is like retain returns an object which you must explicitly release (e.g., in dealloc) in non-garbage collected environments.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-if you use copy then you still need to release that in dealloc.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Use this if you need the value of the object as it is at this moment, and you don't want that value to reflect any changes made by other </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> owners of the object. You will need to release the object when you are finished with it because you are retaining the copy.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@property</span> (<span style="color: #bb2ca2;">nonatomic</span>, <span style="color: #bb2ca2;">copy</span>) NSArray *myArray;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> myArray;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>09. readonly</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-declaring your property as <span style="background-color: #eeeeee;">readonly</span> you tell compiler to not generate setter method automatically.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Indicates that the property is read-only.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-If you specify readonly, only a getter method is required in the <span style="background-color: #eeeeee;">@implementation</span> block. If you use the <span style="background-color: #eeeeee;">@synthesize</span> directive in </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> the <span style="background-color: #eeeeee;">@implementation</span> block, only the getter method is synthesized. Moreover, if you attempt to assign a value using the dot syntax, </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> you get a compiler error.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>readonly<span style="color: black;">) NSString *name;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>10. readwrite </b></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-setter and getter generated.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Indicates that the property should be treated as read/write.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-This attribute is the default.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>-Both a getter and setter method are required in the @implementation block. If you use the @synthesize directive in the implementation </div>
<div style="font-family: Helvetica; font-size: 12px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span> block, the getter and setter methods are synthesized.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example:</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>nonatomic<span style="color: black;">, </span>readwrite<span style="color: black;">) NSString *name;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@synthesize<span style="color: black;"> name;</span></div>
<div>
<span style="color: black;"><br /></span></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com22Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-16022190558297874602012-11-06T07:17:00.000-08:002013-02-25T07:18:17.823-08:00Thread in iOS (Theory)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
Thread in iOS</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
<b>Thread</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
Threads are one of several technologies that make it possible to execute multiple code paths concurrently inside a single application. </div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
Threads are a relatively lightweight way to implement multiple paths of execution inside of an application.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
Inside each program, however, exists one or more threads of execution, which can be used to perform different tasks simultaneously.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
The system itself actually manages these threads of execution, scheduling them to run on the available cores and preemptively interrupting them as needed to allow other threads to run.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
From a technical standpoint, a thread is a combination of the kernel-level and application-level data structures needed to manage the execution of code.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
threads provide a way to increase performance in some types of applications.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<ul>
<li style="font-family: 'Lucida Grande'; font-size: 12px; margin: 0px;">The term <b>thread</b> is used to refer to a separate path of execution for code.</li>
<li style="font-family: 'Lucida Grande'; font-size: 12px; margin: 0px;">The term <b>process</b> is used to refer to a running executable, which can encompass multiple threads.</li>
<li style="font-family: 'Lucida Grande'; font-size: 12px; margin: 0px;">The term <b>task</b> is used to refer to the abstract concept of work that needs to be performed.</li>
</ul>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>1.Cocoa threads</b> : Cocoa implements threads using the <a href="http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html#//apple_ref/occ/cl/NSThread"><span style="color: #3366cc;">NSThread</span></a> class. Cocoa also provides methods on <a href="http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/cl/NSObject"><span style="color: #3366cc;">NSObject</span></a> for spawning new threads and executing code on already-running threads.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>2.POSIX threads</b> : POSIX threads provide a C-based interface for creating threads. If you are not writing a Cocoa application, this is the best choice for creating threads.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>3. Multiprocessing Services</b> : Multiprocessing Services is a legacy C-based interface used by applications transitioning from older versions of Mac OS. Instead, you should use the <span style="color: #666666;">NSThread</span> class or POSIX threads.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
Threads are relatively expensive to create in terms of memory and time.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
<b>Thread States</b> : After starting a thread, the thread runs in one of three main states: running, ready, or blocked.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
If a thread is not currently running, it is either blocked and waiting for input or it is ready to run but not scheduled to do so yet.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
<b>Thread entry-point </b>: When you create a new thread, you must specify an entry-point function/method for that thread.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
<b>Run Loop</b> : </div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
A <b>run loop</b> is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
A run loop puts its thread to sleep when there is nothing to do, it eliminates the need for polling, which wastes CPU cycles and prevents the processor itself from sleeping and saving power.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
To configure a run loop, all you have to do is launch your thread, get a reference to the run loop object, install your event handlers, and tell the run loop to run.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
If you plan to create long-lived secondary threads, however, you must configure the run loop for those threads yourself.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
<b>Thread Synchronization</b> : </div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
<b>Locks (NSLock class)</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
Locks provide a brute force form of protection for code that can be executed by only one thread at a time. The most common type of lock is mutual exclusion lock, also known as a <b>mutex</b>. When a thread tries to acquire a mutex that is currently held by another thread, it blocks until the lock is released by the other thread. </div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px;">
You can use locks to protect a <b>critical section</b> of your code, which is a segment of code that only one thread at a time is allowed access.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
<b>Conditions (NSCondition Class)</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
A condition acts as a gatekeeper, blocking a given thread until the condition it represents becomes true. When that happens, the condition releases the thread and allows it to continue.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
<b>Atomic operations</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Atomic operations are another way to protect and synchronize access to data. Atomic operations offer a lightweight alternative to locks in situations where you can perform mathematical or logical operations on scalar data types. Atomic operations use special hardware instructions to ensure that modifications to a variable are completed before other threads have a chance to access it.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 4px;">
<b>Inter-thread Communication</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
At some point, communication between threads becomes necessary. </div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Creating a multithreaded application is hard. Even if you are very careful and lock shared data structures at all the right junctures in your code, your code may still be semantically unsafe.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
A thread’s job is to do work for your application, but if the results of that job are never used, what good is it? so you need a way to get information from one thread to another.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
There are many ways to communicate between threads.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
<b>1.Direct messaging</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
This capability means that one thread can essentially execute a method on any other thread.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>2.Global variables, shared memory, and objects</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Another simple way to communicate information between two threads is to use a global variable, shared object, or shared block of memory.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Shared variables must be carefully protected with locks or other synchronization mechanisms to ensure the correctness of your code. Failure to do so could lead to race conditions, corrupted data, or crashes.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>3.Conditions (NSCondition Class)</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Conditions are a synchronization tool that you can use to control when a thread executes a particular portion of code. </div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
A thread waiting on a condition remains blocked until that condition is signaled explicitly by another thread.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
4. <b>Run loop</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Run loop sources put your thread to sleep automatically when there is nothing to do, which improves your thread’s efficiency.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
<b>5.Ports and sockets</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Ports and sockets can be used to communicate with external entities, such as other processes and services. so your thread sleeps when there is no data waiting on the port.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>6.Message queues</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>7.Cocoa distributed objects</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>Thread Management :</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<b></b><br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Every application starts with a single thread, which runs the application's <span style="color: #666666; font-family: Courier;">main</span> function. Applications can spawn additional threads, each of which executes the code of a specific function.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
When an application spawns a new thread, that thread becomes an independent entity inside of the application's process space. Each thread has its own execution stack and is scheduled for runtime separately by the kernel. A thread can communicate with other threads and other processes, perform I/O operations, and do anything else you might need it to do. Because they are inside the same process space, however, all threads in a single application share the same virtual memory space and have the same access rights as the process itself.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
<b>Thread Costs:</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Threading has a real cost to your program (and the system) in terms of memory use and performance. Each thread requires the allocation of memory in both the kernel memory space and your program’s memory space. </div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
1. <b>Kernel data structures [ 1 kb] </b>: This memory is used to store the thread data structures and attributes, much of which is allocated as wired memory and therefore cannot be paged to disk.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
2. <b>Stack space [512 KB (secondary threads) 8 MB (OS X main thread) 1 MB (iOS main thread) ] </b>: The minimum allowed stack size for secondary threads is 16 KB and the stack size must be a multiple of 4 KB.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
3. <b>Creation time [90 microseconds] </b>: This value reflects the time between the initial call to create the thread and the time at which the thread’s entry point routine began executing.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>Creating a Thread :</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
There are two ways to create a thread</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>•<span class="Apple-tab-span" style="white-space: pre;"> </span>Use the <span style="font-family: Courier;">detachNewThreadSelector:toTarget:withObject:</span> class method to spawn the new thread. (is supported <span class="Apple-tab-span" style="white-space: pre;"> </span>in all versions of OS X)</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>•<span class="Apple-tab-span" style="white-space: pre;"> </span>Create a new <span style="font-family: Courier;"><b>NSThread</b></span> object and call its <span style="font-family: Courier;">start</span> method. (Supported only in iOS and OS X v10.5 and later.)</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
* Both techniques create a detached thread in your application. A detached thread means that the thread’s resources are automatically reclaimed by the system when the thread exits.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 10px; min-height: 15px;">
<br /></div>
<div style="font-family: Courier; font-size: 13px; margin-bottom: 10px;">
<span style="font-family: 'Lucida Grande'; font-size: 12px;"><b>1. Create Thread using "</b></span><b>detachNewThreadSelector:toTarget:withObject " method</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
To detach a new thread, you simply provide the name of the method (specified as a selector) that you want to use as the thread’s entry point, the object that defines that method, and any data you want to pass to the thread at startup.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Example :</div>
<div style="font-family: Menlo; font-size: 11px;">
[NSThread detachNewThreadSelector:<span style="color: #bb2ca2;">@selector</span>(myThreadMainMethod:) toTarget:<span style="color: #bb2ca2;">self</span> withObject:<span style="color: #bb2ca2;">nil</span>];</div>
<div style="color: #666666; font-family: Courier; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>2. Create Thread using " initWithTarget:selector:object " method</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<b></b><br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
This method takes the exact same information as the <span style="color: #666666; font-family: Courier;">detachNewThreadSelector:toTarget:withObject:</span> method and uses it to initialize a new <span style="color: #666666; font-family: Courier;">NSThread</span> instance. It does not start the thread, however. To start the thread, you call the thread object’s <span style="color: #666666; font-family: Courier;">start</span> method explicitly.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Example :</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSThread</span>* myThread = [[NSThread alloc] initWithTarget:<span style="color: #bb2ca2;">self</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
selector:<span style="color: #bb2ca2;">@selector</span>(myThreadMainMethod:)</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
object:<span style="color: #bb2ca2;">nil</span>];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;">[myThread start]; </span>// Actually create the thread</div>
<div style="font-family: Menlo; font-size: 11px;">
[myThread cancel];</div>
<div style="font-family: Menlo; font-size: 11px;">
[NSThread exit];</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>3. Create Background thread with NSObject class</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
The <span style="color: #3366cc; font-family: Courier;">performSelectorInBackground:withObject:</span> method creates a new detached thread and uses the specified method as the entry point for the new thread.if you have some object ( <span style="color: #666666; font-family: Courier;">myObj</span>) and that object has a method called <span style="color: #666666; font-family: Courier;">doSomething</span> that you want to run in a background thread.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Example:</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
[myObj performSelectorInBackground:<span style="color: #bb2ca2;">@selector</span>(doSomething) withObject:<span style="color: #bb2ca2;">nil</span>];</div>
<div style="color: #666666; font-family: Courier; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #666666; font-family: Courier; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<span style="color: #666666; font-family: Courier; font-size: 12px;">* </span>this method is the same as if you called the <span style="color: #3366cc; font-family: Courier;">detachNewThreadSelector:toTarget:withObject:</span> method of <span style="color: #3366cc; font-family: Courier;">NSThread</span> with the current object.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; margin-bottom: 4px;">
<b>Autorelease Pool</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>Note :</b> you would need to set up an autorelease pool (if you were not using garbage collection) and configure the thread’s run loop if you planned to use it. The autorelease pool catches any objects that are autoreleased from that thread.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Because the top-level autorelease pool does not release its objects until the thread exits, long-lived threads should create additional autorelease pools to free objects more frequently.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Example:</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)doSomething {</div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>*** code that should be run <span style="color: #bb2ca2;">in</span> the <span style="color: #bb2ca2;">new</span> thread goes here ***</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>[pool release];</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Thread Attributes</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
1. change thread stack size</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
Allocate and initialize an <span style="color: #666666; font-family: Courier;">NSThread</span> object (do not use the <span style="color: #3366cc; font-family: Courier;">detachNewThreadSelector:toTarget:withObject:</span> method). Before calling the <span style="color: #666666; font-family: Courier;">start</span> method of the thread object, use the <span style="color: #3366cc; font-family: Courier;">setStackSize:</span> method to specify the new stack size.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>Thread Types:</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
1.Detached threads</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
Most high-level thread technologies create detached threads by default. In most cases, detached threads are preferred because they allow the system to free up the thread’s data structures immediately upon completion of the thread. Detached threads also do not require explicit interactions with your program.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
2.Joinable threads</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
You can think of joinable threads as akin (similar) to child threads.Although they still run as independent threads, a joinable thread must be joined by another thread before its resources can be reclaimed by the system.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="background-color: #f0f3f7; font-family: 'Lucida Grande'; font-size: 13px;">
<span style="background-color: transparent;">* </span>At application exit time, detached threads can be terminated immediately but joinable threads cannot. Each joinable thread must be joined before the process is allowed to exit. Joinable threads may therefore be preferable in cases where the thread is doing critical work that should not be interrupted, such as saving data to disk.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>Thread Priority:</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
you can use the <span style="color: #3366cc; font-family: Courier;">setThreadPriority:</span> class method of <span style="color: #3366cc; font-family: Courier;">NSThread</span> to set the priority of the currently running thread.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="background-color: #f0f3f7; font-family: 'Lucida Grande'; font-size: 13px;">
It is generally a good idea to leave the priorities of your threads at their default values. Increasing the priorities of some threads also increases the likelihood of starvation among lower-priority threads.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px;">
<b>Terminating a Thread:</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
The recommended way to exit a thread is to let it exit its entry point routine normally. Killing a thread prevents that thread from cleaning up after itself. </div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>Using the @synchronized Directive</b></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<b></b><br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; margin-bottom: 10px;">
The <span style="color: #666666; font-family: Courier;">@synchronized</span> directive is a convenient way to create mutex locks on the fly in Objective-C code.</div>
<div style="font-family: 'Lucida Grande'; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="color: #666666; font-family: Courier; font-size: 13px; margin-bottom: 10px;">
Example:</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)myMethod:(<span style="color: #bb2ca2;">id</span>)anObj</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>@synchronized<span style="color: black;">(anObj)</span></div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Everything between the braces is protected by the @synchronized directive.</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="color: #666666; font-family: Courier; font-size: 13px;">
--------------------------------------------------------------------------------</div>
<div style="color: #666666; font-family: Courier; font-size: 13px; min-height: 16px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px;">
<b>Grand Central dispatch (Asynchronous Task) / </b><span style="font-family: Verdana; font-size: 13px;">NSOperations</span></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<b></b><br /></div>
<div style="background-color: #f0f3f7; font-family: 'Lucida Grande'; font-size: 13px;">
<b>Important:</b> GCD is a C level API; it does not catch exceptions generated by higher level languages. Your application must catch all exceptions before returning from a block submitted to a dispatch queue.</div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
<div style="font-family: 'Lucida Grande'; font-size: 12px; min-height: 15px;">
<br /></div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-64976685272330021882012-09-12T03:37:00.000-07:002013-03-25T04:44:51.072-07:00Model-View-Controller (MVC) design pattern in iPhone<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px; text-align: justify;">
<span style="color: #669c35;"><b>Model-View-Controller (MVC)</b></span><b> </b>:A design pattern in which the model (any data in your program), the view (what the user sees), and the controller (a layer that handles all interaction between the view and model) are separated in such a manner that modifying either the view or model component of your program has no effect on one another.<br />
<br />
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Model</b> :The model contains the data.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>View</b> : The view displays information contained in the model.</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>Controller</b> : the controller is responsible for accessing data from the model and displaying it on the view.<br />
<br />
-------------------------- <span style="color: #674ea7;"><b>More Details with Example Got from SO</b></span>--------------------------<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2MJbWEooZMBaCiEOBAxYDTpjFW6q57rZCPn05DgUz1wiB1d65WSe07XYZPuZuyPc4DSyG_AG9PpBlbDpXEbwuPU6MWJiS12rGpIqjy4srkrSw8nzw5ak4wJGaAVlvjjvwRPjpJTKx6s-E/s1600/mvc1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="170" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2MJbWEooZMBaCiEOBAxYDTpjFW6q57rZCPn05DgUz1wiB1d65WSe07XYZPuZuyPc4DSyG_AG9PpBlbDpXEbwuPU6MWJiS12rGpIqjy4srkrSw8nzw5ak4wJGaAVlvjjvwRPjpJTKx6s-E/s320/mvc1.png" width="320" /></a></div>
<br />
<br />
<div style="margin-bottom: 13px;">
<b>Model</b> : is related to a data which we have regarding our application's objects. Example : Application of a Person Contact Details than, Each Person on in Contact will be having it'e own attributes (Name, Address etc.) and that will be saved inside Person model.</div>
<div style="margin-bottom: 13px;">
<b>Controller</b> : is something which controls UI updates. It keeps a reference to Person model and checks for any changes in model, If there is than change the View of that particular person. And it keeps checking for any UI input so it can change data inside Model.</div>
<div style="margin-bottom: 13px;">
<b>View</b> : This is fairly obvious View is all about UIView, What we see on screen.</div>
</div>
<div style="font-family: Helvetica; font-size: 12px;">
<i><span style="color: #6aa84f;"><br /></span></i></div>
<div style="font-family: Helvetica; font-size: 12px;">
</div>
<i><span style="color: #6aa84f;">Below is snap shot, how I follow MVC in my applications</span></i><br />
<br />
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOjowOwkvrl0iQFJrL7z4z2SLafHTk3DjhRc-Udacv15SAyF0JBllvmcEBHVDquymkBhvnY3TN-f8YlDd2BJm-JsCPMc96tvtpruZyf0ifmYfyzNqjdNhasRfV_XWn_ILcQZaZ7jmgI9Zj/s1600/mvc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOjowOwkvrl0iQFJrL7z4z2SLafHTk3DjhRc-Udacv15SAyF0JBllvmcEBHVDquymkBhvnY3TN-f8YlDd2BJm-JsCPMc96tvtpruZyf0ifmYfyzNqjdNhasRfV_XWn_ILcQZaZ7jmgI9Zj/s320/mvc.png" width="179" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; text-align: justify;">
<span style="color: #5e30eb;">Apple Says </span>" The Model-View-Controller (MVC) design pattern assigns objects in an application one of three roles: model, view, or controller. The pattern defines not only the roles objects play in the application, it defines the way objects communicate with each other. Each of the three types of objects is separated from the others by abstract boundaries and communicates with objects of the other types across those boundaries. The collection of objects of a certain MVC type in an application is sometimes referred to as a layer—for example, model layer.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px; text-align: justify;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; text-align: justify;">
MVC is central to a good design for a Cocoa application. The benefits of adopting this pattern are numerous. Many objects in these applications tend to be more reusable "</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy9-bz5LTFkNj6lIhALMvdruehWcH7wnh0V4ZIjGgricUnm4Ho82odKoE9LbKeJhs6IeE1Ca7ImyzERfE8eHYGjFIF1el7pRK0M1ZZecfLEzX7hXLkj1bYsVAmp5Lw7Cc_-EjjtqolYAcm/s1600/iOS_DataManagement.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy9-bz5LTFkNj6lIhALMvdruehWcH7wnh0V4ZIjGgricUnm4Ho82odKoE9LbKeJhs6IeE1Ca7ImyzERfE8eHYGjFIF1el7pRK0M1ZZecfLEzX7hXLkj1bYsVAmp5Lw7Cc_-EjjtqolYAcm/s320/iOS_DataManagement.jpg" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #0056d6; font-family: Helvetica; font-size: 12px;">
<b>Model Objects</b><span style="color: black;"> </span></div>
<div style="font-family: Helvetica; font-size: 12px;">
Model objects encapsulate the data specific to an application and define the logic and computation that manipulate and process that data.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #0061ff; font-family: Helvetica; font-size: 12px;">
<b>View Objects</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
A view object is an object in an application that users can see. A view object knows how to draw itself and can respond to user actions. A major purpose of view objects is to display data from the application’s model objects and to enable the editing of that data. </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #0061ff; font-family: Helvetica; font-size: 12px;">
<b>Controller Objects</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
A controller object acts as an intermediary between one or more of an application’s view objects and one or more of its model objects. Controller objects are thus a conduit through which view objects learn about changes in model objects and vice versa. Controller objects can also perform setup and coordinating tasks for an application and manage the life cycles of other objects.</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764147 76.949115699999979 13.4667827 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-24428214039992060232012-07-15T04:55:00.000-07:002013-04-09T04:56:36.489-07:00How to add Shadow,Border and Round corner to View programatically<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="font-family: Helvetica; font-size: 12px;">
here is simplest way what I do, When I need to add Shadow, Border or Round Corners Effects on any view</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">in </span>ViewController.h</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. add QuartzCore.framwork in your project</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
2. add the UIView in XIB via Interface Builder</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. create UIView's IBOutlet and Hook-up with it</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
@property<span style="color: black;"> (</span>weak<span style="color: black;">, </span>nonatomic<span style="color: black;">) </span>IBOutlet<span style="color: black;"> </span><span style="color: #703daa;">UIView</span><span style="color: black;"> *backgoundWall;</span></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black; font-family: Helvetica; font-size: 12px;">in </span>ViewController.m</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. import QurtzCore header file.</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><QuartzCore/QuartzCore.h></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
3. synthesise the View property variable</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">@synthesize</span> backgoundWall;</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
4. in <b>viewDidLoad</b> method add Shadow </div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">super</span> <span style="color: #3d1d81;">viewDidLoad</span>]; </div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>shadowColor<span style="color: black;"> =[</span>UIColor<span style="color: black;"> </span><span style="color: #3d1d81;">blackColor</span><span style="color: black;">].</span>CGColor<span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>shadowRadius<span style="color: black;"> =</span><span style="color: #272ad8;">3.0</span><span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>shadowOpacity<span style="color: black;"> =</span><span style="color: #272ad8;">0.8</span><span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>cornerRadius<span style="color: black;"> =</span><span style="color: #272ad8;">5.0</span><span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>shadowOffset<span style="color: black;"> =</span><span style="color: #3d1d81;">CGSizeMake</span><span style="color: black;">(</span><span style="color: #272ad8;">0</span><span style="color: black;">, </span><span style="color: #272ad8;">7</span><span style="color: black;">);</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>borderColor<span style="color: black;"> = [</span>UIColor<span style="color: black;"> </span><span style="color: #3d1d81;">lightGrayColor</span><span style="color: black;">].</span>CGColor<span style="color: black;">;</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #4f8187;">backgoundWall</span><span style="color: black;">.</span>layer<span style="color: black;">.</span>borderWidth<span style="color: black;"> =</span><span style="color: #272ad8;">2.0</span><span style="color: black;">;</span></div>
<div style="font-family: Helvetica; font-size: 12px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
5. Here is the result screen</div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeBp0gbS6Mqva8IP_-ef_J6uiqkyp5oCyMuTgPZBmFL8ZqJ1yMmKAx8MXOymaPb-j6-OdJ1esTfEjQoP_IUpFUtxbG_ZJ1GkfYfWyC1YICtOj5mx1dedm-gorQe39HrvxLQswR24ndUUDT/s1600/shadowEffects.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeBp0gbS6Mqva8IP_-ef_J6uiqkyp5oCyMuTgPZBmFL8ZqJ1yMmKAx8MXOymaPb-j6-OdJ1esTfEjQoP_IUpFUtxbG_ZJ1GkfYfWyC1YICtOj5mx1dedm-gorQe39HrvxLQswR24ndUUDT/s320/shadowEffects.png" width="320" /></a></div>
<div style="font-family: Helvetica; font-size: 12px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! We did it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
I would love to here you feedback!!</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-11677117035230549122012-06-02T03:37:00.000-07:002013-04-09T03:40:13.426-07:00Why we use #pragma mark in Objective-C/iPhone code and How to do that?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #9929bd; font-family: Helvetica; font-size: 12px;">1. Why : </span><span style="font-family: Helvetica; font-size: 12px;"> </span><span style="color: #38761d;">use pragma mark to help you organise your code for yourself <span style="font-family: Helvetica; font-size: 12px;"> </span></span><br />
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Let! me make it more clear, When we work on huge projects and our classes contains tons of lines of code.</div>
<div style="font-family: Helvetica; font-size: 12px;">
it's hard to manage all the methods specially when you are looking for any desired method and you need to scroll all the way again and again.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
So #pragma is the way to organise the code, and provide you, Overview of the class showing all the methods, constants, properties etc.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #e32400;">Note:</span> <i>it doesn't affect anything on your code, just for the organising code</i></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<span style="color: #9929bd;">2. How : </span>It's pretty simple when you start writing code just add #pragma above method or block every time when you need it.</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Example :</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
#pragma mark - <i>label name</i><br />
<div style="min-height: 15px;">
<i></i><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
so let's I have some life cycle methods of view controller then I will do like this</div>
<div style="min-height: 15px;">
<i></i><br /></div>
<div style="color: #874efe;">
<span style="color: black;">#pragma mark - </span><i>ViewController's LIfe Cycle Methods</i></div>
<div style="min-height: 15px;">
<i></i><br /></div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 12px;">
3. Here is Example code snip :</div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
------------------------------------------------------------------------------------------------</div>
<div style="min-height: 15px;">
<i></i><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - ViewController's LIfe Cycle Methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)viewDidLoad{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>viewDidLoad<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">void</span>)didReceiveMemoryWarning{</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">super</span><span style="color: black;"> </span>didReceiveMemoryWarning<span style="color: black;">]; </span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#pragma mark - Button Click methods</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">IBAction</span>)goButtonPressed:(<span style="color: #bb2ca2;">id</span>)sender { </div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>readMeViewController<span style="color: black;"> = [[</span>ReadMeViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">initWithNibName</span><span style="color: black;">:</span><span style="color: #d12f1b;">@"ReadMeViewController"</span><span style="color: black;"> </span><span style="color: #3d1d81;">bundle</span><span style="color: black;">:</span><span style="color: #bb2ca2;">nil</span><span style="color: black;">];</span></div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>readMeViewController<span style="color: black;">.</span>readMeControllerDelegate<span style="color: black;"> = </span><span style="color: #bb2ca2;">self</span><span style="color: black;">;</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">readMeViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Helvetica; font-size: 12px;">
------------------------------------------------------------------------------------------------</div>
<div style="font-family: Helvetica; font-size: 12px;">
and whenever I need to look for my class overview just press <span style="color: #669c35; font-size: 14px;"><b>ctrl+6</b></span><span style="color: #669c35;"><b> </b></span>and below is the result</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 12px;">
4. result (class overview) :</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghyphenhyphenjMFGe5OCi3VFAlrLwD97OhzczF0LBG8mNMqZwglbS0vIv9_z5GEAwNysO86kSJ1jpfwRGBX7ntsBZNl5rCCqIdL_DozOk9myh7T-9EUv0vM0xMEL1iNym6bSIelS87BEkGFIv0u9_Zn/s1600/pragma.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghyphenhyphenjMFGe5OCi3VFAlrLwD97OhzczF0LBG8mNMqZwglbS0vIv9_z5GEAwNysO86kSJ1jpfwRGBX7ntsBZNl5rCCqIdL_DozOk9myh7T-9EUv0vM0xMEL1iNym6bSIelS87BEkGFIv0u9_Zn/s320/pragma.png" width="226" /></a></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Cheers!! we will use it from now ..Happy Coding :)</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987tag:blogger.com,1999:blog-3946099568107655302.post-70881033028295360702012-05-22T02:42:00.000-07:002013-05-24T06:33:15.035-07:00iPhone Tips and Tricks<div dir="ltr" style="text-align: left;" trbidi="on">
<b style="font-family: Helvetica; font-size: 12px;"><span style="color: #6aa84f;">How to disable ARC in Xcode for Latest iOS Applications</span></b><br />
<div style="color: #4f7a28; font-family: Helvetica; font-size: 12px; min-height: 14px;">
<b></b><br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1. Select Project --> Builds Phases -->Compile Sources</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
double click and File for which you want to disable ARC --> In pop window paste this command</div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>-fno-objc-arc</b></div>
<div style="font-family: Helvetica; font-size: 12px;">
That's it, Build project, Enjoy!!<br />
<br />
<br />
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
<div style="color: #6aa84f; min-height: 14px;">
<b></b><br /></div>
<div style="color: #6aa84f;">
<b>How to get Current Device Info (like it is iPhone,iPad or iPhone Simulator etc.)</b></div>
<div style="color: #4f7a28; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
Just use the Below code and you will get return string as</div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">NSString</span> *deviceType = [[<span style="color: #703daa;">UIDevice</span> <span style="color: #3d1d81;">currentDevice</span>] <span style="color: #3d1d81;">model</span>];</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"My Current Device is : %@"<span style="color: black;">,deviceType);</span></div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
iPhone Device Name <span class="Apple-tab-span" style="white-space: pre;"> </span>= <span class="Apple-tab-span" style="white-space: pre;"> </span>" iPhone "</div>
<div style="color: #232323;">
iPhone Simulator Name <span class="Apple-tab-span" style="white-space: pre;"> </span>= <span class="Apple-tab-span" style="white-space: pre;"> </span>" iPhone Simulator "</div>
<div style="color: #232323;">
iPad Simulator Name <span class="Apple-tab-span" style="white-space: pre;"> </span>= <span class="Apple-tab-span" style="white-space: pre;"> </span>" iPad Simulator "</div>
<div style="color: #232323;">
iPod Device Name <span class="Apple-tab-span" style="white-space: pre;"> </span>= <span class="Apple-tab-span" style="white-space: pre;"> </span>" iPod touch " </div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b><span style="color: #6aa84f;">Show/Hide Hidden Files on Your Mac</span></b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 12px;">
1. Show Hidden files</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Launch the Terminal (you can find Terminal this way)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go --> Utilities - > Terminal</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 paste this command</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>defaults write com.apple.Finder AppleShowAllFiles TRUE</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.3 Hit Enter</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.4 now for restart Finder hit below command</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>killall Finder</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="color: #9929bd; font-family: Helvetica; font-size: 12px;">
2. Hide Hidden files</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.1 Launch the Terminal (you can find Terminal this way)</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
Go --> Utilities - > Terminal</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.2 paste this command</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>defaults write com.apple.Finder AppleShowAllFiles FALSE</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
1.3 Hit Enter</div>
<div style="font-family: Helvetica; font-size: 12px;">
1.4 now for restart Finder hit below command</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br /></div>
<div style="font-family: Helvetica; font-size: 12px;">
<b>killall Finder</b></div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br />
<div>
<b><span style="color: #6aa84f;">How to Create Button programatically</span></b></div>
<div style="min-height: 14px;">
<br /></div>
1. add below code in viewDidLoad method of ViewController<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;"><span class="Apple-tab-span" style="white-space: pre;"> </span>UIButton</span><span style="color: black;"> *button = [</span><span style="color: #703daa;">UIButton</span><span style="color: black;"> </span>buttonWithType<span style="color: black;">:</span>UIButtonTypeRoundedRect<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [button </span>addTarget<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>action<span style="color: black;">:</span><span style="color: #bb2ca2;">@selector</span><span style="color: black;">(buttonPressed) </span>forControlEvents<span style="color: black;">:</span>UIControlEventTouchUpInside<span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [button </span>setTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@"My Button"</span><span style="color: black;"> </span>forState<span style="color: black;">:</span>UIControlStateNormal<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
button.<span style="color: #703daa;">frame</span> = <span style="color: #3d1d81;">CGRectMake</span>(<span style="color: #272ad8;">80.0</span>, <span style="color: #272ad8;">210.0</span>, <span style="color: #272ad8;">160.0</span>, <span style="color: #272ad8;">40.0</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
[<span style="color: #bb2ca2;">self</span>.<span style="color: #703daa;">view</span> <span style="color: #3d1d81;">addSubview</span>:button];</div>
<div style="min-height: 14px;">
<br /></div>
2. add this method and Go for Execute the code for desired output.<br />
<div style="min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) buttonPressed{</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"My Button pressed."<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
</div>
<div style="font-family: Helvetica; font-size: 12px; min-height: 14px;">
<br />
<br />
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
<div style="color: #6aa84f; min-height: 14px;">
<b></b><br /></div>
<div style="color: #6aa84f;">
<b>How to get Current Device Orientation (like It's Portrait or Landscape etc.)</b></div>
<div style="color: #4f7a28; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
Just use the Below code and you will get result</div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;">[[</span><span style="color: #703daa;">UIDevice</span><span style="color: black;"> </span>currentDevice<span style="color: black;">] </span>beginGeneratingDeviceOrientationNotifications<span style="color: black;">];</span></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
UIInterfaceOrientation<span style="color: black;"> orientationType = [</span>UIDevice<span style="color: black;"> </span><span style="color: #3d1d81;">currentDevice</span><span style="color: black;">].</span>orientation<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Device's Current Orientation is : %d"<span style="color: black;">,orientationType);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">if</span>(orientationType == <span style="color: #272ad8;">0</span>){</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//this is really a just a failsafe.</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Orientation is in :Default Portrait :"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}<span style="color: #bb2ca2;">else</span> <span style="color: #bb2ca2;">if</span>(orientationType == <span style="color: #272ad8;">1</span>){ </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Orientation is in : Portrait :"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}<span style="color: #bb2ca2;">else</span> <span style="color: #bb2ca2;">if</span>(orientationType == <span style="color: #272ad8;">2</span>){ </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Orientation is in : Portrait UpsideDown :"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}<span style="color: #bb2ca2;">else</span> <span style="color: #bb2ca2;">if</span>(orientationType == <span style="color: #272ad8;">3</span>){ </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Orientation is in : Landscape Left :"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px;">
}<span style="color: #bb2ca2;">else</span> <span style="color: #bb2ca2;">if</span>(orientationType == <span style="color: #272ad8;">4</span>){ </div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #3d1d81;">NSLog</span><span style="color: black;">(</span>@"Orientation is in : Landscape Right :"<span style="color: black;">);</span></div>
<div style="font-family: Menlo; font-size: 11px;">
} </div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
<br />
<br />
<div style="color: #669c35;">
<b>How to change Navigation Bar's Background colour and Title programatically</b></div>
<div style="min-height: 14px;">
<br /></div>
add below code in viewDidLoad :<br />
<div style="color: #be38f3;">
1. update tint color</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//set Green Colour</div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>navigationController<span style="color: black;">.</span>navigationBar<span style="color: black;">.</span>tintColor<span style="color: black;"> = [</span>UIColor<span style="color: black;"> </span><span style="color: #3d1d81;">colorWithRed</span><span style="color: black;">:</span><span style="color: #272ad8;">34</span><span style="color: black;">/</span><span style="color: #272ad8;">255.0f</span><span style="color: black;"> </span><span style="color: #3d1d81;">green</span><span style="color: black;">:</span><span style="color: #272ad8;">139</span><span style="color: black;">/</span><span style="color: #272ad8;">255.0f</span><span style="color: black;"> </span><span style="color: #3d1d81;">blue</span><span style="color: black;">:</span><span style="color: #272ad8;">34</span><span style="color: black;">/</span><span style="color: #272ad8;">255.0f</span><span style="color: black;"> </span><span style="color: #3d1d81;">alpha</span><span style="color: black;">:</span><span style="color: #272ad8;">1</span><span style="color: black;">];</span></div>
<div style="min-height: 14px;">
<br /></div>
<div style="color: #be38f3;">
2. add title</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">title</span><span style="color: black;"> = </span>@"Welcome Screen"<span style="color: black;">;</span></div>
<br />
<br />
<div style="color: #669c35;">
<b>How to add Bar-Button on Navigation Bar</b></div>
<div style="min-height: 14px;">
<br /></div>
1. Make sure you have already added Navigation Bar controller in application<br />
<div style="min-height: 14px;">
<br /></div>
2. Create UIBarButton<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIBarButtonItem</span><span style="color: black;"> *signIn_BarButton = [[</span><span style="color: #703daa;">UIBarButtonItem</span><span style="color: black;"> </span>alloc<span style="color: black;">]</span>initWithTitle<span style="color: black;">:</span><span style="color: #d12f1b;">@" SIGN IN "</span><span style="color: black;"> </span>style<span style="color: black;">:</span>UIBarButtonItemStyleBordered<span style="color: black;"> </span>target<span style="color: black;">:</span><span style="color: #bb2ca2;">self</span><span style="color: black;"> </span>action<span style="color: black;">:</span><span style="color: #bb2ca2;">@selector</span><span style="color: black;">(signInUser)];</span></div>
<div style="color: #272ad8; font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">UIColor</span><span style="color: black;"> *button_color = [</span><span style="color: #703daa;">UIColor</span><span style="color: black;"> </span><span style="color: #3d1d81;">colorWithRed</span><span style="color: black;">:</span>109.0<span style="color: black;">/</span>255.0<span style="color: black;"> </span><span style="color: #3d1d81;">green</span><span style="color: black;">:</span>152.0<span style="color: black;">/</span>255.0<span style="color: black;"> </span><span style="color: #3d1d81;">blue</span><span style="color: black;">:</span>136.0<span style="color: black;">/</span>255.0<span style="color: black;"> </span><span style="color: #3d1d81;">alpha</span><span style="color: black;">:</span>1.0<span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
signIn_BarButton.<span style="color: #703daa;">tintColor</span> =button_color;</div>
<div style="min-height: 14px;">
<br /></div>
3. Add it to Navigation Bar Controller (on right side)<br />
<div style="min-height: 14px;">
<br /></div>
<div style="color: #703daa; font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">self</span><span style="color: black;">.</span>navigationItem<span style="color: black;">.</span>rightBarButtonItem<span style="color: black;"> =signIn_BarButton;</span></div>
<div style="min-height: 14px;">
<br /></div>
4. Add the method for Button click<br />
<div style="min-height: 14px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">void</span>) signInUser{</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
</div>
<div style="color: #4f8187; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>signInViewController<span style="color: black;"> = [[</span>SignInViewController<span style="color: black;"> </span><span style="color: #3d1d81;">alloc</span><span style="color: black;">] </span><span style="color: #3d1d81;">init</span><span style="color: black;">];</span></div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> [</span><span style="color: #bb2ca2;">self</span><span style="color: black;">.</span><span style="color: #703daa;">navigationController</span><span style="color: black;"> </span>pushViewController<span style="color: black;">:</span><span style="color: #4f8187;">signInViewController</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #bb2ca2;">YES</span><span style="color: black;">];</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="min-height: 14px;">
<br /></div>
5. here is the result screen<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH3GgYoiszI9sA8zG6vkDNV-i3NJEDt56UwxUIpwt3y4-F7W4kPiGyxLHE1tvewKoNrB90EkaAzDJ8KufuNuqkN2nJ73MMmg5KLOFYoVBFHwBn2azMPoY_mweRIAcsUXmsPC2T0vH-8Glu/s1600/barButton.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="17" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH3GgYoiszI9sA8zG6vkDNV-i3NJEDt56UwxUIpwt3y4-F7W4kPiGyxLHE1tvewKoNrB90EkaAzDJ8KufuNuqkN2nJ73MMmg5KLOFYoVBFHwBn2azMPoY_mweRIAcsUXmsPC2T0vH-8Glu/s320/barButton.png" width="320" /></a></div>
<br />
<br />
<br />
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
<div style="color: #6aa84f; min-height: 14px;">
<br /></div>
<div style="color: #6aa84f;">
<b>Handle Screen Orientations in iOS 5 and iOS 6 </b></div>
<div style="color: #4f7a28; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//For up-to iOS 5.0</div>
<div style="font-family: Menlo; font-size: 11px;">
- (<span style="color: #bb2ca2;">BOOL</span>)shouldAutorotateToInterfaceOrientation:(<span style="color: #703daa;">UIInterfaceOrientation</span>)interfaceOrientation</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>// Return YES for supported all orientations</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #bb2ca2;">return</span> (interfaceOrientation == <span style="color: #3d1d81;">UIInterfaceOrientationPortrait</span>);</div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//For iOS 6.0</div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #703daa;">NSInteger</span>)supportedInterfaceOrientations</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>//Supporting only portrait orientation.</div>
<div style="color: #3d1d81; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span><span style="color: #bb2ca2;">return</span><span style="color: black;"> </span>UIInterfaceOrientationMaskPortrait<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
-(<span style="color: #bb2ca2;">BOOL</span>)shouldAutorotate</div>
<div style="font-family: Menlo; font-size: 11px;">
{</div>
<div style="color: #bb2ca2; font-family: Menlo; font-size: 11px;">
<span style="color: black;"> </span>return<span style="color: black;"> </span>NO<span style="color: black;">;</span></div>
<div style="font-family: Menlo; font-size: 11px;">
}</div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
<br />
<br />
<div style="color: #6aa84f;">
<b>How to disable NSLog in Xcode for Production stage</b></div>
<div style="color: #4f7a28; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
Add <span style="color: #78492a; font-family: Menlo; font-size: 11px;">#define NSLog </span> in <b>appName-Prefix.pch</b> file in Supporting Files Folder of your project</div>
<div style="color: #232323;">
and result file code look like..</div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
// Prefix header for all source files of the 'NSLog' target in the 'NSLog' project</div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;">#import </span><Availability.h></div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#ifndef __IPHONE_4_0</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#warning "This project uses features only available in iOS SDK 4.0 and later."</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#endif</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#ifdef __OBJC__</div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;"> #import </span><UIKit/UIKit.h></div>
<div style="color: #d12f1b; font-family: Menlo; font-size: 11px;">
<span style="color: #78492a;"> #import </span><Foundation/Foundation.h></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#endif</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
//Add this to disable NSLog</div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px;">
#define NSLog</div>
<div style="color: #232323; min-height: 14px;">
<br /></div>
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
<br />
<div style="color: #669c35;">
<br />
<div style="color: #008400; font-family: Menlo; font-size: 11px;">
<br />
<div style="color: #6aa84f; font-family: Helvetica; font-size: 12px;">
<b>How to Get Current Device Width and Hieght</b></div>
</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">CGRect</span> screenRect = [[<span style="color: #703daa;">UIScreen</span> <span style="color: #3d1d81;">mainScreen</span>] <span style="color: #3d1d81;">bounds</span>];</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">CGFloat</span> screenWidth = screenRect.<span style="color: #703daa;">size</span>.<span style="color: #703daa;">width</span>;</div>
<div style="font-family: Menlo; font-size: 11px;">
<span style="color: #703daa;">CGFloat</span> screenHeight = screenRect.<span style="color: #703daa;">size</span>.<span style="color: #703daa;">height</span>;</div>
<div style="font-family: Menlo; font-size: 11px; min-height: 13px;">
<br /></div>
<div style="color: #232323;">
--------------------------------------------------------------------------------------------------------------</div>
</div>
</div>
</div>
RDChttp://www.blogger.com/profile/09071971836590859058noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.476417699999999 76.949115699999979 13.4667797 78.240009699999987