SQLite3 and UITableView

Discussion in 'iOS Programming' started by jweinraub, Jul 12, 2013.

  1. jweinraub macrumors 6502


    Jun 26, 2007
    Sol III

    I am still learning the ropes of iOS development. I am new to Xcode (more versed in C#/C++ in Visual Studio... i know i know)

    I am trying to make a simple app that has data in a locally stored SQLite database. Say it is called printers. Printers has the uid (pk), printer model, toner model, and quantity for example. I like to group it based on printer models, and each section under the group all the toners for each model. I am fairly decent at SQL, but I do not understand anything about the UITableView and how to populate it from a database notwithstanding.

    So, I already have all the neccessary items intalled to develop such, but how do I one, access the database, and two, place the elements from
    the database onto the userinterface? The group header should be the printer model, and each element is toner for that model, so obviously most of them will have one item, but the colour printers or the higher end models will have the colours and other consumables.

    I haven't decided what action will occur when I click the model. I was hoping the quantity would be easily be there, but not sure yet.
    And obviously I will have a way of adding/decrementing units.

    But this is a solo project that I am building on my own, not for sale, not for business, just something to teach me the ropes of databases
    so I can better learn iOS development.

    But I had googled around and found no tutorial that really helps me to do what I want. Obviously I am not asking you guys to code everything
    for me, but I really don't know where to start in getting the data from sqlite into uitableview.


    PS- Perhaps property lists/dictionaries are a better way of doing this, but I had always liked using databases for my C# projects (but those were desktop apps where it went to a remote mysql database)
  2. truehybridx macrumors member

    Dec 6, 2010
  3. chown33 macrumors 604

    Aug 9, 2009
    You can learn how to use UITableView using any data source, whether that's plists or SQL databases. Don't limit your search to just table-views using SQL databases. That's an unnecessary restriction.

    I googled the single search term UITableView and found plenty of tutorial websites, along with Apple's class reference, which then has a link to their Table View Programming Guide. That's the first thing I tried, and it seemed to produce usable results. What have you tried? Be specific.

    After you know how UITableView works, and can consistently make it use any given data source, then the way to interface to a SQL database should become a lot clearer. That's the point at which you can look for SQLite tutorials, because it should then be clear how to make SQL queries that act as a data source.

    On the other hand, if you don't know what a UITableView is expecting from a data source, or when or why it calls on the data source, then knowledge of SQL won't help at all.
  4. jweinraub thread starter macrumors 6502


    Jun 26, 2007
    Sol III
    I think that is a good point, master the UITableView first, then worry about the data sources later. I tried following a guide where it populated it all by arrays, and it crashed the simulator, so I either did it wrong or didn't pay close enough of attention.

    So I had tried to learn via example/imitation. I should pickup a decent iOS book - that way I can have a book next to me on a computer rather than switching from Xcode to Safari and back.
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    There's a lot to learn about UITableView. Every book or online course covers it extensively. You should go that route of learning.

    Connecting a database to a tableview is a matter of putting the row data from the database into a form suitable for use as the data model of the table view. You need to understand tableviews to understand the form of data model that's appropriate.

Share This Page