Monday, August 1, 2011

iOS 5 Tutorial - Part I. SQLite + UITableView + UISearchBar Tutorial

     There are many ways to retrieve and store data on the iPhone, from property lists to NSCoding, from SQLite to Core Data. I thought that after trying to learn all three that SQLite was the easiest to learn. This three-part tutorial series is going to cover how to fill a UITableView with data from a SQLite database and then incorporate a UISearchBar. I really thought there were no good tutorials on all three so I thought I should create my own. 


     In this first part of the tutorial we will create a sqlite database and then read the values from the database and create an array of objects to fill the tableviews in the future tutorial. This first tutorial can really apply to anything where you have to read from a database and then create an array of objects.


1. Suppose you have a csv file of buildings with the fields id, name, latitude, longitude, type. You will need to convert this to a sqlite database. Place the buildings.csv file on the desktop. 







2. Open a terminal window and with the buildings.csv file on the desktop execute the following commands. 






3. Then you should see something like the following. 






Note: I converted everything to type text. I thought it was much more difficult later on to convert number types and everything is a lot easier to deal with that way. 


4. Create a new Master-Detail Application called buildings. Then drag and drop the buildings.sqlite file into your project folder. Then add the libsqlite3.dylib framework to your project. Click the buildings project at the top of the far left column. 


i.e. buildings > Building Phases > Link Binary With Libraries > + > libsqlite3.dylib 










5. For organizational purposes drag and drop the .dylib file into your frameworks folder. 


6. Then create a new building object called Building which is a subclass of NSObject. 






7. Now go to your buildingsAppDelegate (.h/.m) and add the code below.





8. Now with the added code you should NSLog the values from the values retrieved from the database. Most of the code is commented/ self-explanatory so I will not go into depth about what everything does here. 


It's important to correctly NSLog the values to ensure that you are doing it correctly. Now that you've read from the database correctly you can now move on to filling the UITableView. 


Note: The first battle is to ensure that your program is correctly reading from the database. If you can retrieve the values from the database and the objects look like they make sense, then you can move on. 


Debugging Tip #1: Print out the values that were retrieved from the database.


Debugging Tip #2: Print out the values in the fields of the objects. Sometimes objects are not allocated or set properly and this will save you a lot of headache in the future.  


My Error 1:


Code: NSLog(@"Name: %@, Latitude:%g Longitude: %g", name, latitude, longitude);


Discussion: Since the variable type in my object was of type NSString the output was incorrect since I used (%g) which is for doubles. 




Debugging Output 1: This is what my output looked like when I printed the values that were retrieved from the database.




Debugging Output 2: This is what my output looked like when I printed the values that were retrieved from the objects in the items array. 















89 comments :

LLacour said...

This is a great example project but i didn't get any data in my table view.

Nick said...

Hi, is part 2 and 3 available. I liked this tutorial and was hoping to see the other 2.

thanks
Nick

Joaquin Cubero said...
This comment has been removed by the author.
Frank said...
This comment has been removed by the author.
Frank said...
This comment has been removed by the author.
Frank said...

7. Now go to your buildingsAppDelegate (.h/.m) and add the code below.


NO CODE..


8. Now with the added code..

Xcode_Noobie said...

Hello,

This tutorial illustrates exactly what I'm trying to accomplish! I have it all working however I cant for the life of me figure out the next part... how to get the data into my tableview. Right now I have an NSMutableArray declared in my viewDidLoad() with some hardcoded values. Then in cellForRowAtIndexPath i set the cell.textLabel.text equal to the objectAtIndex:indexPath.row of the array I setup. I want to however remove this code and use the data that I've pulled from the database...

Can you PLEASEEEE post information on how to do this? Much Appreciated!

dom said...

I get an 'AppDelegate undeclared' error. WHy?

Kosicki said...

Please, how to feed my tableview with the elements of sqlite? thanks.

Kathiresan Muthu said...

Hi this is Kathiresan i am having 3 years of experience as a dot net developer and i am certified. i have knowledge on OOPS concepts in .NET but dont know indepth. After learning android will be enough to get a good career in IT with good package? and i crossed Android Training in Chennai website where someone please help me to identity the syllabus covers everything or not??

Thanks,
kathiresan

Kathiresan Muthu said...

Hi this is Kathiresan i am having 3 years of experience as a dot net developer and i am certified. i have knowledge on OOPS concepts in .NET but dont know indepth. After learning android will be enough to get a good career in IT with good package? and i crossed Android Training in Chennai website where someone please help me to identity the syllabus covers everything or not??

Thanks,
kathiresan

vignesh m said...

Hi this is java i am having 3 years of experience as a java developer and i am certified. i have knowledge on OOPS concepts in java but dont know indepth. After learning hadoop will be enough to get a good career in IT with good package? and i crossed hadoop training in chennai website where someone please help me to identity the syllabus covers everything or not??

thanks, vignesh

Ganesh said...

Hi, this is Ganesh I am having 3 years of experience as a Dot Net developer and I am certified. I have Knowledge on OOPS Concepts in .NET indepth. After learning Salesforce will be enough to get a good career in IT with good Package? and i crossed Salesforce Training in Chennai website where someone please help me to identify the syllabus covers everything or not??

Thanks,
Ganesh

Ganesh said...

Hi, this is Ganesh I am having 3 years of experience as a Dot Net developer and I am certified. I have Knowledge on OOPS Concepts in .NET indepth. After learning Salesforce will be enough to get a good career in IT with good Package? and i crossed Salesforce Training in Chennai website where someone please help me to identify the syllabus covers everything or not??

Thanks,
Ganesh

Abinaya Vijayaram said...


Hi this is abinaya i am having 3 years of experience as a java developer and i am certified. i have knowledge on OOPS concepts in java but dont know indepth. After learning oracle will be enough to get a good career in IT with good package? and i crossed Oracle Training in Chennai website where someone please help me to identity the syllabus covers everything or not??

Thanks, abinaya

Abinaya Vijayaram said...

Hi this is abinaya i am having 3 years of experience as a java developer and i am certified. i have knowledge on OOPS concepts in java but dont know indepth. After learning oracle will be enough to get a good career in IT with good package? and i crossed oracle training chennai website where someone please help me to identity the syllabus covers everything or not??

Thanks, abinaya

dwara kesh said...

Hi this is dwarakesh i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know
indepth. After learning java will be enough to get a good career in IT with good package? and i crossed
java training in chennai website where someone please help me to identity the syllabus covers everything or not??

thanks, dwarakesh

dwara kesh said...


Hi this is dwarakesh i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know
indepth. After learning java will be enough to get a good career in IT with good package? and i crossed
java training in Chennai website where someone please help me to identity the syllabus covers everything or not??

thanks, dwarakesh

Rajesh Ravi said...


Hi this is Rajesh i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know indepth. After learning Dot Net will be enough to get a good career in IT with good package? and i crossed dot net training in chennai website where someone please help me to identity the syllabus covers everything or not??

thanks,
Rajesh

Rajesh Ravi said...

Hi this is Rajesh i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know indepth. After learning Dot Net will be enough to get a good career in IT with good package? and i crossed dot net training in chennai website where someone please help me to identity the syllabus covers everything or not??

thanks,
Rajesh

Roshini Balu said...

i got some useful information here, and you given good examples for every topics keep sharing...
salesforce training in Chennai

Victoria John said...

Your posts is really helpful for me.Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.If anyone wants to get Dot Net Training in Chennai reach FITA, rated as No.1 Dot Net Training Institutes in Chennai.

Martina Christy said...

Your blog is really awesome. Thanks for sharing this blog. If anyone want to get Best PHP Training in Chennai, please visit Fita academy located at Chennai, Velachery.

rebeka christy said...

I get a lot of great information from this blog. Recently I did oracle certification course at a leading academy. If you are looking for best Oracle Training in Chennai visit FITA IT training and placement academy which offer best SQL Training in Chennai.

Emi Jackson said...

Hi I am Emi lives in Chennai. I am a technology freak. Recently I did Best Java Training in Chennai at a leading Java Training Institutes in Chennai. This is really helpful for me to make a bright carrer in IT industry.

Andry BZ said...

Thanks for sharing these niche piece of coding to our knowledge. Here, I had a solution for my inconclusive problems & it’s really helps me a lot keep updates…Informatica training in chennai
Informatica training center in Chennai

jack wilson said...

Salesforce Course in Chennai


I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job . If anyone want to get Salesforce Training in Chennai, Please visit FITA academy located at Chennai Velachery.

Salesforce Developer Training in Chennai

Salesforce Admin Training in Chennai


christina jeni said...

Oracle Training

The information you posted here is useful to make my career better keep updates..If anyone want to become an oracle certified professional reach FITA Oracle Training Center in Chennai, which offers Best Oracle Course in Chennai with years of experienced professionals.

christina jeni said...

Oracle Training Center in Chennai

I get a lot of great information from this blog. Recently I did oracle certification course at a leading academy. If anyone interested to learn best Oracle Course in Chennai visit FITA academy which offer SQL Training in Chennai.



Martina Christy said...

Software Testing Training in Chennai

Hi, I have read your blog. Your information is really useful for me.Thanks for sharing this blog. I did QTP Training in Chennai at Fita training and placement academy which offer best Selenium Training in Chennai with years of experienced professionals. This is really useful for me to make a bright career.

christina jeni said...

Big Data Training Chennai

I get a lot of great information from this blog. Thank you for your sharing this informative blog. Just now I have completed hadoop certification course at a leading academy. If you are looking for best Hadoop Training in Chennai visit FITA IT training and placement academy which offer Big Data Training in Chennai.

rebeka christy said...

HTML5 Training

Hi, Thanks for sharing this valuable blog.I was really impressed by reading this blog. I did HTML5 Training in Chennai at reputed HTML5 Training Institutes in Chennai. This is really useful for me to make a bright future in designing field.

HTML Training in Chennai

jhansi joe said...

The information you have given here is truly helpful to me. CCNA- It’s a certification program based on routing & switching for starting level network engineers that helps improve your investment in knowledge of networking & increase the value of employer’s network, if you want to take ccna course in Chennai get into FITA, thanks for sharing…
ccna training in Chennai | ccna training institute in Chennai

Martina Christy said...

Salesforce Course in Chennai


I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job . If anyone want to get Salesforce Training in Chennai, Please visit FITA academy located at Chennai Velachery. Rated as No.1 Salesforce Training Institutes in Chennai.

Salesforce Developer Training in Chennai | Salesforce Admin Training in Chennai

mathew delport said...

Testing Training in Chennai

Its really awesome blog..If anyone wants to get Software Testing Training in Chennai visit FITA IT academy located at Chennai. Rated as No.1 Software Testing Training Institutes in Chennai

Software Testing Course in Chennai

Emi Jackson said...

Hi, I am Emi lives in Chennai. I am technology freak. I did Android mobile application development course in Chennai at reputed training institutes, this is very usful for me to make a bright carrer in IT industry. So If you looking for best Android Training Institute in Chennai please visit fita academy which offers real time Android Training in Chennai at reasonable cost.

dhanamlakshmi palu said...

I got a useful information here.Its very useful for me.Nice tutorial. Thanks.
SEO Training in chennai|SEO Training chennai

surangacloud said...
This comment has been removed by the author.
surangacloud said...
This comment has been removed by the author.
surangacloud said...

This is certainly one of the most valuable article. Great tips from beginning to till end. Lot of information are available here.Super article.

Cloud Computing Training in chennai | Cloud Computing Training chennai

john son said...

Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.If anyone wants to get Dot Net Training in Chennai reach FITA, rated as No.1 Dot Net Training Institute in Chennai.

john son said...

Hi, I have read your blog and I got a useful information from this blog. Thanks for sharing, keep posting..Salesforce is a cloud based CRM software. Today's most of the IT industry use this software for customer relationship management.
Regards
Salesforce Training | Salesforce.com Training in Chennai

Chandrika Madapudi said...

Your blog is really awesome and I got some useful information from your blog. This is really useful for me. Thanks for sharing such a informative blog. Keep posting.

Regards..
Cloud Computing Training Centers in Chennai

Roshini RS said...

Thanks for sharing; Salesforce crm cloud application provides special cloud computing tools for your client management problems. It’s a fresh technology in IT industries for the business management.
Salesforce training institute in Chennai | Salesforce training

Sathik Ali. A said...

GREAT INFO ABOUT MOBILE APPS. I AM PLANNING TO DO iOS Training at IICT Chromepet. Please sugesst me where they cover all the required topics.

Their course syllabus link is provided below:

http://www.traininginchrompet.com/apple-ios-training-in-chennai.aspx

Please revert me as soon as possible guys. I heard IICT Chromepet is the best iOS Training Institute in Chennai.

Martina Christy said...

Thanks for sharing this excellent post. Its really very informative and interesting. Keep update your blog. For a best Android training in Chennai please refer this site.
Regards....
Android Training in Chennai

Roshini RS said...

Well post in recent day’s customer relationship play vital role to get good platform in business industry, Salesforce crm tool helps you to maintain your customer relationship enhancement.
Regards,
Salesforce training institutes in Chennai|Salesforce courses in Chennai

Bay Max said...

There are lots of information about latest technology and how to get trained in them, like Hadoop Training Chennai have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies(Hadoop Training in Chennai). By the way you are running a great blog. Thanks for sharing this.

Arjun kumar said...

Oracle Database Training will help you develop a thorough understanding of Oracle Database, as well as its related products. With more than 50 Database offerings, enhance your knowledge of Database 11g, MySQL, Data Guard, and more.
SQL Training in Chennai
Oracle Training in Chennai

Amirtha rao said...

Thanks for sharing this niche useful informative post to our knowledge, Actually SAP is ERP software that can be used in many companies for their day to day business activities it has great scope in future.
Regards,
SAP training in chennai|SAP Course in Chennai|sap institutes in Chennai

Steve Hawks said...

You have stated definite points about the technology that is discussed above. The content published here derives a valuable inspiration to technology geeks like me. Moreover you are running a great blog. Many thanks for sharing this in here.

Salesforce Training in Chennai
Salesforce Certification
Salesforce Training

Harshita said...

Thank you so much for the informative post. I used it as a reference to train my students.
HTML5 Training in Chennai | HTML5 Training in Chennai

Shashaa Tirupati said...

This is exactly what I was searching for. Awesome post. Thanks a bunch. Helped me in taking class for my students. Wish to follow your posts, keep writing! God Bless!
Shashaa
Dot Net training institutes in Chennai | Dot Net training institutes in Chennai | Dot Net training institutes in Chennai

Yashika said...

Thanks for sharing This valuable information.Also See My Academy Website Best ios training in Chennai

Ashwini Suresh said...

Hello admin, thank you for your informative post on hadoop training in Chennai. It helped a lot in training my students during our hadoop training Chennai sessions. We at Fita, provide big data training in Chennai for students who are interested in choosing a career in big data.

caroline jesi said...

It’s too informative blog and I am getting conglomerations of info’s. Thanks for sharing; I would like to see your updates regularly so keep blogging. If anyone looking car just get here
Regards,
sas training in Chennai|sas course in Chennai|sas institutes in Chennai

mathew delport said...


Nice Article! Mostly I have gathered knowledge from the blogger, because its provides more information over the books & here I can get more experienced skills from the professional, thanks for taking your to discussing this topic.
Regards,
Oracle DBA Training in Chennai|Oracle Training|Oracle Training Institute in Chennai

for IT the said...

Great Article
Java Online Training | Java EE course

Java Training in Chennai | J2EE Training in Chennai | java j2ee training institutes in chennai ~ Java Course in Chennai | Java Training Institutes in Chennai

Java 360 | IT Technical Articles |Java Training Institutes

Priya said...

Really interesting content which is unique which provided me the required information.
JAVA Training in Chennai | Best Java Training Institute in Chennai | FITA Academy Chennai | FITA Training .

geethu said...

Really interesting content which is unique which provided me the required information.
Dot Net Training in Chennai | .Net training in Chennai | FITA Training | FITA Velachery .

varshini devi said...

If you are beginner you can use this blog to get knowledge about IOS, i really felt great with this information, keep sharing
Regards,

SAS Training in Chennai|Python Training in Chennai|Fita Chennai reviews

Rohit Kumar said...

Packers and Movers Hyderabad
Packers and Movers Pune
Packers and Movers Bangalore

Rohit Kumar said...

Packers and Movers Mumbai
Packers and Movers Delhi
Packers and Movers Gurgaon

Rohit Kumar said...

Packers and Movers Chennai
Packers and Movers Noida
Packers and Movers Navi Mumbai
Packers and Movers Thane
Packers and Movers Ghaziabad
Packers and Movers Faridabad

Fathima Fazal said...

Great tutorial..Very useful information and i am planning to do ios training in chennai can anyone help me out in choosing best ios training institute in chennai.

Abhi K said...

Best packers and movers in Kolkata, household shifting service in Kolkata, home relocation in Kolkata, car carriers service in Kolkata, car transport in Kolkata. packers and movers Kolkata

Jeanne Davies said...

Excellent post and wonderful blog, I really like this type of interesting articles keep it you.ecommerce web designing

M Sunny said...

our site is a powerful IVR software for interactive voice response, voicemail & call attendant phone systems; supporting caller ID logging and multi-line support in this site IVR For Sale

sushilkr said...



Packers and Movers Hyderabad
Packers and Movers Bangalore
Packers and Movers Pune
Packers and Movers Gurgaon

sushilkr said...


Packers and Movers in Hyderabad
Packers and Movers in Bangalore
Packers and Movers in Pune
Packers and Movers in Gurgaon

Roshini Fita said...

Excellent post!!! In this competitive market, customer relationship management plays a significant role in determining a business success. That too, cloud based CRM product offer more flexibility to business owners to main strong relationship with the consumers.
Regards,
Salesforce Training in Chennai|Salesforce Training|salesforce developer training in chennai

Priya said...

The Salesforce CRM system is a business tool that allows to manage the customers, partners and prospect information in one place. The companies nowadays use salesforce CRM tool to close bigger deals faster.
salesforce training in chennai | salesforce training institute in chennai

Brn Infotech said...

I’m eager to find the valuable information and for me this is the right place to get the good stuff.
Iphone training institute in hyderabad

Brn Infotech said...

Nice blog ..! I really loved reading through this article.. Thanks for sharing such a amazing post with us and keep blogging...
ios training institute in hyderabad

Brn Infotech said...

I just want to say that all the information you have given here is awesome. Thank you
best ios training institute

Brn Infotech said...

I really didn’t know all these things before which you have informed us through your best writing.
Best ios training in hyderabad

Nikshitha S said...

The strategy you have posted on the oracle hepled me to get into the next level of this technology and had lot of informations in it.
oracle training in chennai | oracle training institutes in chennai

Nikshitha S said...

Nice informative content on the latest technology and the placement is very important for the students to get placed in good companies.
training institutes in chennai with placement | Placement training in chennai

Nikshitha S said...


Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
digital marketing course in Chennai | digital marketing training in Chennai

Nikshitha S said...

Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
Python Training in Chennai | Python Course in Chennai

Eva said...



Wow! That's really great information guys.I know lot of new things here. Really great contribution.Thank you .

apple iphone service center in chennai

http://packersmoversbangalore-in.blogspot.in/ said...

I must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1...Please visit our wonderful and valuable website:
Packers And Movers in Bangalore

Adlearning Technologies said...

Thank You for sharing your article. I like it. We provide TIBCO Online Training in Hyderabad

Packers Movers Gurgaon said...

We Provide Best Packers And Movers Gurgaon List for Get Free Best Quotes, Compare Charges,
Save Money And Time, Household Shifting Services @ Packers-and-Movers-Gurgaon.in
Packers And Movers Gurgaon
Packers And Movers In Gurgaon

Neemu NA said...

Thanks for the sharing useful information content
Hi we at Colan Infotech Private Limited , a company which is Situated in US and India, will provide you best java web service and our talented
java application development. team will assure you best result and we are familiar with international markets, We work with customers in a wide variety of sectors. Our talented team can handle all the aspects of
Java web application development,we are the best among the
Java development company.
We have quite an extensive experience working with
java development services.
we are the only Java application development company which offer custom services to a wide range of industries by exceeding our client’s expectations. You can even interact directly with the team regarding your project, just as you would with your in-house team.Our pro team will provide you the best
java appliaction development services.
We are best among the
java development companies in Chennai,
please review our customer feedbacks so that you may find a clue about us. If you want one stop solution for java development outsourcing, Colan infotech is the only stop you need to step in. Colan Infotech is the unique
java web development company.were our team of unique
java application developer
were ranked top in
java enterprise application development.

Neemu NA said...

Thanks for sharing useful information article to us keep sharing this info,
Hi We at Colan Infotech Private Limited a
Mobile application development company in chennai,
is Situated in US and India, will provide you best service in
enterprise mobile app development company .
and Colan Infotech has a group of exceedingly dedicated, inventive and creative experts with an energy for delivering exciting , helpful and stylish Web and Mobile Applications, We work with customers in a wide variety of sectors.
We design all of our websites and applications using the responsive web design approach. Our talented team can handle all the aspects of mobility so we are rated as best service provider in
Mobile apps development companies in chennai.
We solidly trust that our customers start things out and there is not a viable alternative for quality of service.
We offer custom services to a wide range of industries by exceeding our client’s expectations. You can even interact directly with the team regarding your project, just as you would with your in-house team. we always desire to solicit our customer's fruitful experience with us, we are the top notch
Mobile App Development Company in chennai
and mobile app development companies in Bangalore. We can provide best
mobile app development chennai .
We can provide cutting edge technology services in
Mobile application development in chennai.
Reach us for mobile app development chennai or just call us for best
mobile app developers in chennai .

Karthika Shree said...

This is a great article, I have been always to read something with specific tips! I will have to work on the time for scheduling my learning.
IOS Training in Chennai

Priya Kannan said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
Dot Net Training in Chennai

Brn Infotech said...


Awesome,
Thank you so much for sharing such an awesome blog...
iphone training institute in hyderabad